Print address of variable using pointer in c is a simple program to print address of variable using pointer.
In this tutorial we are going to learn pointers in c, how to print address of variable using pointer variable, Print address of variable using pointer in c and program to print address of variable using pointers.
what is pointers in c
Pointer is a variable which stores address of another variable.
syntax for pointers in c
In above syntax, data type is type of variable we want to store pointer.
And pointername is name of pointer variable, * indicates it’s pointer variable.
Example :- int *ptr;
Accessing value of variable:-
We can access value of variable by using variable name or by address of variable.we can access value by using pointer as it stores address of the variable.
& Address of operator gives the address of variable.
* gives the value at that address stored in pointer variable.
Concept you need to know from c
1. Basic input and output in c
Algorithm to print address of variable using pointer
2. Declare variable and Pointer variable
3. Print address of variable
Program to Print address of Variable Using Pointer in C
int i,*j,**k; i=45; j=&i; k=&j;
printf("Values in variables\n");
printf("Value in i %d\n",i);
printf("Value in j which is the address of i %d\n",j);
printf("Value in k which is the address of j %d\n",k); //Lets see what is the real address of i,j,k
printf("Address of i which is value in j %u\n",&i);
printf("Address of j which is the value in k %u\n",&j);
printf("Address of k %u\n",&k); //printing using pointer
1. Write header files to file.
2. Start with writing main function.
3. Declare variable
i => int variable
j => pointer variable
k => pointer to pointer
4. Print actual value stored in variable
i = 5
i = 45
j = 1000 => address of i (address can be anything)
k = 2000 => address of j (address can be anything )
5. We can print address of variables
i = 500
j = 1000
k = 2000