Pointers in C++

Pointers in C++

Pointers in C++ are variables that store the memory addresses of another variable. It is the symbolic representation of the address.

They enable programs to simulate call-by-reference as well as to create and manipulate dynamic data structures and the pointer holds the address of an object stored in memory. The pointer simply means “points” to the object.

Declaring a pointer

 ∗ (asterisk symbol) is used to declare the pointer

int ∗   a; //pointer to int    
char ∗  c; //pointer to char

 

Address in C++

Program of Pointers in C++

#include <iostream>
using namespace std;

int main()
{
    int var1 = 3;
    int var2 = 24;
    int var3 = 17;

    cout << "Address of var1: "<< &var1 << endl;

   
    cout << "Address of var2: " << &var2 << endl;

   
    cout << "Address of var3: " << &var3 << endl;
}

Output

Address of var1: 0x7fff5fbff8ac
Address of var2: 0x7fff5fbff8a8
Address of var3: 0x7fff5fbff8a4

 

Read more, Operator Overloading in C++

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *