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++
#include <iostream>using namespace std;int main(){int var1 = 3;int var2 = 24int var3 = 17;cout << &var1 << endl;cout << &var2 << endl;cout << &var3 << endl;}
Output
0x7fff5fbff8ac 0x7fff5fbff8a8 0x7fff5fbff8a4C++ Inheritance
Comments
Post a Comment
Thanks for your message