Print address of variable using pointer in c is a simple program to print the address of a variable using a pointer.

Pointers in c
The pointer is a variable that stores address of another variable.
Syntax for pointers in c
<Datatype> *pointername;
In the above syntax, a data type is the type of variable we want to store pointer.
And pointername is the name of a pointer variable, * indicates it’s pointer variable.

Example:- int *ptr;

Accessing the value of a variable:-
We can access the value of a variable by using the variable name or by the address of the variable. we can access the value by using a pointer as it stores the address of the variable.
& Address of operator gives the address of the variable.
* gives the value at that address stored in the pointer variable.

Pointer representation

Pointer

Algorithm to print address of variable using pointer

  1. Declare variable and Pointer variable
  2. Print address of variable

Program to the Print address of Variable Using Pointer in C

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
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("Addresses\n ");
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


}

Output :

Print address of variable using pointer

Write A Comment