Published on : 3rd Oct 2021

Pointer in C programming
Pointer is an important concept in C programming. A programmer must have to know the concept of pointer.
Why do we need pointer ?
We cannot return more than one value from a function. But, we can return an address. An array is nothing but a pointer. So, we can return an array that can store more than one value. We don't pass an entire array to a function rather we pass the base address of an array to a function using pointer.
Definition :
A pointer is a variable which is used to store the address or reference of another variable.
Pointer declaration :
int *p;
Here, p is a pointer which can store the value of an int type variable.
Pointer declaration with initialization :
int a = 100;
int *p = &a;
Visualization of pointer :

Note : The address of a variable may vary because OS allocate memory for a variable at the time of execution.
Explanation :
Here, p is storing the address of a. So, p is pointing to a. Hence, p is a pointer.
Source Code :
#include <stdio.h> int main(int argc, char** argv) { int a = 100; int *p = &a; printf("Address of a = %u\n", &a); printf("Value of p = %u\n", p); printf("Value at address %u = %d\n", p, *p); return 0; }
Output :
Address of a = 6487572 Value of p = 6487572 Value at address 6487572 = 100