C++: \: Data Type and address of


As we know that the variables are the place holders for different types of data, must be stored somewhere in the computer (as a memory) that would be accessible by the compiler. In C++ "&" operator provides the memory location. Below is an example of displaying, data type and addresses (physical location) of those data.

#include <iostream>
#include <string>
using namespace std;
int main()
int variable = 24;
char letter = 'A', another_letter = 'B';
string str = "hello";
char more_letter ='C';
cout <<"hello world--from cout "<<
variable << "\t"<<letter << "\n"<< str <<endl;
cout <<" size of char letter " << sizeof(letter) <<"\n";
cout <<" address of char letter " << &letter <<"\n";
cout <<" address of char letter " << &another_letter <<"\n";
cout <<" size of int variable " << sizeof(variable) <<"\n";
cout <<" address of int variable " << &variable <<"\n";
cout <<" size of string str " << sizeof(str) <<"\n";
cout <<" address of string str " << &str <<"\n";
cout <<" address of char letter " << &more_letter <<"\n";
return 0;