Generally I know pointer is use to store address of variable. I can write basic program for pointer but I am still confuse I don't understand actually what's the real real use of pointer and where we will use pointer in programming.
Compiler output
The value of variable is: 10
The address of variable : 0061FF2C
The value of pointer : 0061FF2C
The address of pointer : 0061FF28
int variable = 10; // address = 0061FF2C, data = 10
int *pointer = &variable; // address = 0061FF28, data = 0061FF2C
How do you know that you have to use pointer in program and where do we use pointer in program?
Code:
#include <stdio.h>
int main(void)
{
int variable = 10;
int *pointer = &variable;
printf("The value of variable is: %d \n", variable);
printf("The address of variable : %p \n", &variable);
printf("The value of pointer : %p \n", pointer);
printf("The address of pointer : %p \n", &pointer);
return 0;
}
Compiler output
The value of variable is: 10
The address of variable : 0061FF2C
The value of pointer : 0061FF2C
The address of pointer : 0061FF28
int variable = 10; // address = 0061FF2C, data = 10
int *pointer = &variable; // address = 0061FF28, data = 0061FF2C
How do you know that you have to use pointer in program and where do we use pointer in program?