In programming, variable is used to hole the value & this variable stored in a memory. Each variable has a address to identify where these variables actually stored in a memory.
In a C programming language, pointer is a variable which can hold the address of another variable.
Accessing Address of Variable
In a system every memory location has its address & we can access the address using ampersand (&) operator.
This ampersand (&) operator denotes an address in memory.
Ex:
int i = 20;
char c = ‘a’;
In the above example, there are two variable i & c.
Integer variable “i” stores the value 10 at memory location 1024(for example) and character variable “c” stores the value ‘a’ at memory location 1026.
1 2 3 4 5 6 7 8 9 | #include<stdio.h> int main() { int i=20; int c='a'; printf("\n value of variable i= %d", i ); printf("\n value of variable c= %c", c ); } |
OUTPUT
1 2 | value of variable i= 20 value of variable c= a |
If we want to print the address of variable ‘i and c’ then we need ampersand (&) operator .
#includeOUTPUT
1 2 | Address of variable i = 1641813104 Address of variable c= 1641813108 |
Note: When you run this program, address are printed might be different.
Example: Write a program to print the address of the variable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <stdio.h> int main () { int v1; char v2; float v3; printf("\n Address of variable v1= %d", &v1 ); printf("\n Address of variable v2= %d", &v2 ); printf("\n Address of variable v3= %d", &v3 ); return 0; } |
OUTPUT
1 2 3 | Address of variable v1= 1174657312 Address of variable v2= 1174657313 Address of variable v3= 1174657308 |
Note: Each and every time when you run this program these variables stored in a different memory location.
Pointer Variable
pointer variable is hold the address of another variable.
Declare a pointer variable
To declare a pointer variable, there must use a * (Asterisk) before variable name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> int main () { int i= 20; // declare & initialize variable i int *ptr; // declare a pointer variable ptr ptr = &i; // ptr (pointer variable) holds the address of variable i. printf("\n Address of variable i= %d", &i ); printf("\n Address of variable i= %d", ptr ); return 0; } |
OUTPUT
1 2 | Address of variable i= 511276620 Address of variable i= 511276620 |
Value at address

In the above example, there are two variable, first is normal variable ‘i’ & pointer variable ‘ptr’.
Integer variable “i” stores the value 10 at memory location 1024(for example) and pointer variable “ptr” stores the address of variable ‘i’ at memory location 2322
Example
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> int main () { int i= 10; // declare & initialize variable i int *ptr; // declare a pointer variable ptr ptr = &i; // ptr (pointer variable) holds the address of variable i. printf("\n value of variable i= %d", *ptr ); return 0; } |
OUTPUT
1 | value of variable i= 10 |
Note: Pointer variable “ptr” prints the address of variable and “*ptr” prints the value of i. *variable name (*ptr) is also called value at address.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include<stdio.h> int main() { int a=4; int *b; b = &a; printf("\n Address of a = %d", &a); printf("\n Address of a = %d", b); printf("\n Address of b = %d", &b); printf("\n Value of b = %d", b); printf("\n Value of a = %d", a); printf("\n Value of a = %d", *(&a)); printf("\n Value of a = %d", *b); return 0; } |
OUTPUT
1 2 3 4 5 6 7 | Address of a = 2464 Address of a = 2464 Address of b = 2466 Value of b = 2490 Value of a = 4 Value of a = 4 Value of a = 4 |
Note: When you run this program, address are printed might be different.