#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;
}
Value: 5
Address: 37814048
Press any key to continue . . .
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); 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.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.