Home / Programs / Print address of a variable
Programming Example

Print address of a variable

👁 1,092 Views
💻 Practical Program
📘 Step by Step Learning
Print address of a variable: A pointer is a variable that holds a memory address. This address is the location of another object (typically another variable) in memory. In another way we can say, A p

Program Code

#include <stdio.h>
int main()
{
  int var = 5;
  printf("Value: %d\n", var);
  printf("Address: %u\n", &var); //Notice, the ampersand(&) before var.
  return 0;
}

Output

Value: 5
Address: 37814048
Press any key to continue . . .

Explanation

Before you get into the concept of pointers, let's first get familiar with address in C.

If you have a variable var in your program, &var will give you its address in the memory, where & is commonly called the reference operator.

You must have seen this notation while using scanf() function. It was used in the function to store the user inputted value in the address of var.

scanf("%d", &var);

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.