#include #include using namespace std; void objectPointers(){ vector *v = new vector; cout << "Address: " << v << endl; for( int i = 0; i < 10; i++ ){ (*v).push_back(i); } cout << "Address: " << v << endl; for( int i = 0; i < (*v).size(); i++ ){ cout << (*v).at(i) << endl; } cout << "Address: " << v << endl; } void objectPointersBetterApproach(){ vector *v = new vector; for( int i = 0; i < 10; i++ ){ v->push_back(i); } for( int i = 0; i < v->size(); i++ ){ cout << v->at(i) << endl; } } void objectPointersBestApproach(){ vector *v = new vector; for( int i = 0; i < 10; i++ ){ v->push_back(i); } for( int i = 0; i < v->size(); i++ ){ cout << v->at(i) << endl; } delete v; } void objectPointers2(){ // pointer to vector, initially points to random location vector *vPtr; // declare and initialize default vector object on stack vector vec; // copies address of stack object into variable that holds addr vPtr = &vec; vPtr->push_back(10); vPtr->push_back(20); for( int i = 0; i < vec.size(); i++ ){ cout << i << ": " << vec[i] << endl; } cout << "Address: " << vPtr << endl; } void precedence(){ int x = 10; int *pX = &x; cout << "Address: " << pX << endl; cout << "x: " << x << endl; cout << "*pX: " << *pX << endl; (*pX)++; cout << "Address: " << pX << endl; cout << "x: " << x << endl; cout << "*pX: " << *pX << endl; *pX++; cout << "Address: " << pX << endl; cout << "x: " << x << endl; cout << "*pX: " << *pX << endl; } void fun() { int x = 10; int *pX = &x; cout << "pX: " << pX << endl; cout << "*pX: " << *pX << endl; cout << "&*pX: " << &*pX << endl; cout << "&pX: " << &pX << endl; cout << "*&pX: " << *&pX << endl; cout << "**&pX: " << **&pX << endl; } int main(){ fun(); }