Print address of a variable

C Programming Language / Pointer in C Language

1057

Program:

#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);

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.