Wednesday, May 18, 2011

Learn C++ by examples (Pointers)

donghua@rh6:~/tmp$ cat pointer_example.cpp
#include

using namespace std;

int main ()
{
int x; // a normal integer
int *p; // a point to an integer

p = &x; // read it, "assign the address of x to p"
cin>>x; // put a value in x, we could also use *p here
cin.ignore();
cout<< *p <<"\n";// note the use of * to get/dereferencing the value
cin.get();
}

No comments:

Post a Comment