In this tutorial we learn &(ampersand) means reference in c programming. Mostly it used to receive data by help of scanf() to store a particular address.
Address In C:
If you declare a variable like,
int a;
then “&a” is a address of that variable means address of memory.
Generally, we are using address number of times while declaring “scanf()” used to read the data and store in a particular memory location. Like
scanf("%d", &a);
Here, the above declaration means the value or data entered by user and store in a variable “a”, Let’s take in below Example:
//In C #include<stdio.h> int main() { int a=10; printf("The address of variable a:%p\n",&a); printf("The value of variable a:%d\n",a); return 0; }
//Output: a=236478 a=10
Note: In each time you will get a different address to run the above code.
Lingaraj Senapati
But In C++ case we are using the address(reference) “&” to print:
//In C++ #include<iostream> using namespace std; int main() { int a=2; cout<<&a; return 0; }
//Output: 0x3435fff538a4253
If you find any issue and interested to rewrite it then contact us.