Saturday, December 31, 2022

C program to print Memory Address of a variable

In C program, we use variables to store some value. Value of any variables are stored in a memory.

We can print memory address using following two methods:
  • By using address of (&) operator
  • By using pointer variable
 "%p" is a format specifier to print a memory address in C language.

Let's see a program to print a memory address of a variable.


#include<stdio.h>

int main(){
	int number=5;
	float percen = 80.5;
	
	printf("Memory address of number variable: %p \n", &number);
	printf("Memory address of percen variable: %p", &percen);
	
	return 0;
}

Output of Program

Memory address of number variable: 000000051FE1C
Memory address of percen variable: 000000051FE18

Note:

You will get different memory address as output in your program execution.
At every run your output may change.





No comments:

Post a Comment