What are the Uses of Pointers in C?

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

In C, the pointer is a variable used for storing the address of a variable. The variable can be of any type such as int, char, array, etc. The pointer size depends on the computer architecture, however, for a 32-bit system, the pointer used is 2 bytes.

Following are the usage of pointers in C:

  • For passing the argument by using references.
  • For accessing the elements of an array.
  • For dynamic memory allocation by using malloc() and calloc() functions .
  • Used in arrays, functions to improve the performance of code.
  • For returning multiple values.
  • Implementing a data structure.
  • For doing system-level programming.

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

What are the Features of Pointers in C?

Following are the features of using pointers in C:

  • It saves the space of memory.
  • The execution time of code is faster when using a pointer since the data are manipulated by using an address, which is also used for direct access to the memory location.
  • By using pointers, memory can be accessed efficiently because a pointer is used for assigning as well as releasing memory. Hence it can be concluded that the memory of the pointers is located dynamically
  • It can be used with a data structure for representing two or multi-dimensional arrays.
  • By using a pointer, an array of any type can be accessed.
  • Has a feature for file handling.
  • Can allocate memory dynamically.
  • If any pointer is declared in the base class, it could access the object of the derived class, however, the opposite of that is not possible.

Examples of the Uses of Pointers in C

Example 1:

Program of using a pointer for printing the address as well as the value of a number.

Output:

/tmp/FcdQjRVXxM.o
The address of n is 2807cc 
The value of n is 13 

Explanation:

The variable n stores the address of the number in a variable. The variable p contains the address of the number. Here * is used to dereference a pointer therefore if we print *p, we will get the value stored at the address contained by p.

Example 2:

C program of assigning a pointer to another variable.

Output:

Explanation:

Here, 3 is assigned to the variable b. And, the address of b is assigned to the pointer.

Example 3:

C program for changing the value pointed by other pointers.

Output:

Explanation:

In this, first, we have assigned the address of b to the pointer. Then, we changed the value of b to 1. Since a and the address of b are the same, *a gives us 1.

Sharpen Your Fundamentals with Free Learning

Learn More about Pointers in C

Pointers in C

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Conclusion

  • In C, the pointer is a variable used for storing the address of a variable. The variable can be of any type such as int, char, array, etc. The pointer size depends on the computer architecture, however, for a 32-bit system, the pointer used is 2 bytes.
  • Following are the usage of pointers in C:
    • For passing the argument by using references.
    • For accessing the elements of an array.
    • For dynamic memory allocation by using malloc() and calloc() functions .
    • Used in arrays, and functions to improve the performance of code.
    • For returning multiple values.
    • Implementing a data structure.
    • For doing system-level programming.
    • For accessing the elements of an array.
    • For dynamic memory allocation by using malloc() and calloc() functions .
    • Used in arrays, functions to improve the performance of code.
    • For returning multiple values.
    • Implementing a data structure.
    • For doing system-level programming.