Address Of Operator in C Programming Language

Notes:

Address of (or Referencing) operator (&): in c programming language
- is used to get address (or reference) of a variable, or a constant (i.e. a read only variable)

Syntax:
&variableName

Example Code: Displaying value and address of a variable

#include <stdio.h>
int main()
{
int a=10, b=20;
printf("Value of a= %d\n",a); // 10
printf("Address of a= %p\n",&a); //0022FF1C
printf("Address of a= %d\n",&a); // 2293532
printf("\n");
printf("Value of b= %d\n",b); // 20
printf("Address of b= %p\n",&b); // 0022FF18
printf("Address of b= %d\n",&b); // 2293528

return 0;
}

Note: Address of operator is used to
- read a value from the keyboard and assign it to some variable
- assign address of a variable to a pointer and modify the value in it using pointer
- pass address of a variable to a function and modify the value in it
etc.

Example Code: Program to find addition of 2 numbers

#include <stdio.h>
int main()
{
int a=0, b=0, c=0;
printf("Enter a value for a:");
scanf("%d",&a); // 30
printf("Enter a value for b:");
scanf("%d",&b); // 40
c = a + b;
printf("Value of c= %d\n",c); // Value of c=70
return 0;
}