Pointer Example in C++


  • The integer variable x is initialized to 10.
  • A pointer p is declared, which can store the address of an integer variable.
  • The address of x is assigned to pointer p using the address-of operator '&'.
  • The values of x, &x, p, &p, and *p are printed using cout statements.
    • x: value of x
    • &ab;x: address of x
    • p: value of pointer p (which is the address of x)
    • &ab;p: address of pointer p
    • *p: value stored at the memory location pointed to by p (which is the value of x)

Source Code

#include<iostream>
using namespace std;
int main()
{
    int x=10;
    int *p;
    p=&x;
    cout << "X : "<<x<<endl;
    cout << "&X : "<<&x<<endl;
    cout << "P : "<<p<<endl;
    cout << "&P : "<<&p<<endl;
    cout << "*P : "<<*p<<endl;
    return 0;
}
To download raw file Click Here

Output

X : 10
&X : 0x7ffd640f347c
P : 0x7ffd640f347c
&P : 0x7ffd640f3480
*P : 10

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples