#include #include using namespace std; struct Point { double x,y; }; int main() { int *p; p = NULL; // initialize with 0 int x = 2; p = new int;//p now points to some garbage integer *p = x + 1;//change the value p points to to be x+1 (3) p[0] = 5; //de-referencing a pointer *p = 4; // same as p[0] = 4; cout << p << endl; cout << p[0] << endl; string *ps; string myString = "ic210"; ps = new string; *ps = "tigers"; *ps = myString; p = &x; //&x gets the address of x; p now points to x *p = 5; //this will change x, since p points to x cout << p << endl; cout << &x << endl; cout << p[0] << endl; cout << x << endl; //pointers to structs Point myPoint; Point* pPointer; pPointer = new Point; (*pPointer).x = 5; (*pPointer).y = 10; pPointer->x = 5; //easier notation; widely used pPointer->y = 10; return 0; }