View Address of Variable in C

View the address in the memory of a variable in C programming by using the ampersand(&) sign before the variable name to print the address in the memory of the variables.

Program Printing Address of Variable

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int var = 5;
printf("Value: %d\n", var);
printf("Address: %d", &var); //Notice, the ampersand '&' before var.
getch();
}
Output
Value: 5
Address: 1703752

Program Printing Address of Variables

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int  var1;
char var2[10]; //this is array.
printf("Address of var1 variable: %x\n", &var1); //printing 'var1' and
printf("Address of var2 variable: %x\n", &var2); //'var2' address.
getch();
}
Output
Address of var1 variable: 19ff48
Address of var2 variable: 19ff3c