View the address in the memory of a variable in C++ programming by using the ampersand(&) sign before the variable name to print the address in the memory of the variable.
#include<iostream.h>
#include<conio.h>
void main()
{
int var = 5;
cout<<"Value: "<<var<<endl;
cout<<"Address: "<<&var; //Notice, the ampersand '&' before var.
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int var1;
char var2[10]; //this is array.
cout<<"Address of var1 variable: "<<&var1<<endl; //printing 'var1' and
cout<<"Address of var2 variable: "<<&var2; //'var2' address.
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
auto int i = 1; //assigning value to auto 'i'.
{
auto int i = 2; //assigning value to another auto 'i'.
{
auto int i = 3; //assigning value to another auto 'i'.
cout<<i<<endl; //printing 'i' value'3'.
}
cout<<i<<endl; //printing 'i' value'2'.
}
cout<<i; //printing 'i' value'1'.
getch();
}