Home C Programming Language / Programs / Print address of a variable
🚀 Programming Example

Print address of a variable

👁 1,093 Views
💻 Practical Program
📘 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
No previous program
No next program

💻 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;
}
                        

🖥 Program 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);
No previous program
No next program
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.