Hi,
I'm new to C++. I wrote this simple program to help other understand the basic of Pointer. I has not been proofread but I hope it will help you.
Code:/* this program demonstrates the use of a pointer the variables x and y are printed then the pointer gets the address where each are stored. It prints that addresses. The pointer is then refererenced by *pname and gets the value of each variable through the pointer */ #include <iostream> using namespace std; int main () { int x = 3; //declare and initialize the variables int y = 7; int *pname; //declare a pointer cout << x << endl; //prints 3 the value held in x pname = &x; //the pointer gets address where x is stored cout << pname << endl; // print the address where x is stored cout << * pname << endl; //prints the value held in x cout << y << endl; //prints 7 the value held in y pname = &y; //pointer gets address where y is stored cout << pname << endl; //prints the address where y is stored cout << *pname << endl; //prints the value held in y return 0; }