Skip to main content

Pointer in c++

Address in C++

To understand pointers, you should first know how data is stored on the computer.
Each variable you create in your program is assigned a location in the computer's memory. The value the variable stores is actually stored in the location assigned.
To know where the data is stored, C++ has an & operator. The & (reference) operator gives you the address occupied by a variable.
If var is a variable then, &var gives the address of that variable.

Example 1: Address in C++

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int var1 = 3;
  6. int var2 = 24
  7. int var3 = 17;
  8. cout << &var1 << endl;
  9. cout << &var2 << endl;
  10. cout << &var3 << endl;
  11. }
Output
0x7fff5fbff8ac
0x7fff5fbff8a8
0x7fff5fbff8a4C++ Inheritance

Comments