Wednesday, May 18, 2011

Learn C++ by examples (Pointers)

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

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
cout<< *p <<"\n";// note the use of * to get/dereferencing the value

No comments:

Post a Comment