Print address of a variable in C
This is a simple program that prints the address of a variable in C programming language.
In the main function, an integer variable,a is defined.
Using the ampersand (&) operator, its address is printed.
The format specifier %p is used to print the address of the variable a.
#include <stdio.h>
int main(void)
{
int a;
printf("Address of a: %p\n", &a);
return 0;
}
The output will print the address of the variable, a in hexadecimal format. The address printed may be different in different execution cycles.
💡
Address of a: 0x7fff7ee50514