Pointer Example in C++


Description:

The variable that stores the address of another variable (like foo in the previous example) is what in C++ is called a pointer. Pointers are a very powerful feature of the language that has many uses in lower level programming.

Example Program:

Here is the simple program pointer in C++.

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

Basic Programs


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



Learn All in Tamil © Designed & Developed By Tutor Joes