Simple Pointer Example Program In C++
On this page (7sections)
Definition
The pointer is a one of the C++ programming language data-type whose value refers directly to (or “points to”) another value stored elsewhere in the computer memory using its address.
Pointer Variable Assign Syntax:
pointer_vaibale = &variable;
C++ Example Pointer Program:
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int i = 10;
int *Ptr;
Ptr = &i;
cout << "\nValue Of i :" << i;
cout << "\nAddress Of i :" << i;
cout << "\nValue Of Ptr :" << Ptr;
cout << "\nAddress Of Ptr :" << &Ptr;
cout << "\nPtr's Pointer Value:" << *Ptr;
cout << "\nPtr Equal to &i :" << *(&i);
}
Sample Output
Value Of i :10
Address Of i :10
Value Of Ptr :0x6dfefc
Address Of Ptr :0x6dfef8
Ptr's Pointer Value:10
Ptr Equal to &i :10
(Output may vary based on system and its memory)
How It Works
This C++ program demonstrates Simple Pointer. It first prepares the data it needs, then performs the core operation step by step, and finally prints the output shown in the Sample Output above.
- Declare the variables that hold the program’s data.
- Print the final result to the console so you can compare it with the sample output.
Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.
Related Pages
- Pointers — Browse all Pointers.
- C++ Pointer Example Programs — Programs — pointer arithmetic and arrays.
Frequently Asked Questions
What does this C++ program do?
It is a C++ example program that demonstrates Simple Pointer, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses core C++ syntax, illustrating a common pattern in C++ programming.