#include // Read this program and think about what will // be printed. Then compile this program with // your favorite compiler, and explain the results. // For the latest version of Borland C++ you may need to // add using namespace std; here. // You also may need to change (unsigned) to (unsigned int) . // This code can be found at // http://www.ccs.neu.edu/home/sbratus/com1101/ int main(){ double x = 43.0; double y = 57.0; double z; double * p; // pointers to double double * q; double * r; p = &x; q = &y; r = &z; // (unsigned) before the pointer name makes the pointer print as // an unsigned positive integer cout << "p = " << (unsigned) p << endl; cout << "q = " << (unsigned) q << endl; *r = *p; *p = *q; *q = *r; cout << "x = " << x << endl; cout << "y = " << y << endl << endl; //--------------------------------------------------- int i; int * p1; p1 = &i; cout << "p1 = " << (unsigned) p1 << endl; p1 = p1 + 1; cout << "p1 = " << (unsigned) p1 << endl; cout << "size of int = " << sizeof(int) << endl << endl; double t; double * p2; p2 = &t; cout << "p2 = " << (unsigned) p2 << endl; p2 = p2 + 1; cout << "p2 = " << (unsigned) p2 << endl; cout << "size of double = " << sizeof(double) << endl << endl; char ch; char * p3; p3 = &ch; cout << "p3 = " << (unsigned) p3 << endl; p3 = p3 + 1; cout << "p3 = " << (unsigned) p3 << endl; cout << "size of char = " << sizeof(char) << endl << endl; //--------------------------------------------------- int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int * ptr; ptr = a; for( int k=0; k<10; k++ ){ cout << *ptr << " "; ptr++; } cout << endl; ptr = a; for( int j=0; j<10; j++ ){ *ptr = -( *ptr ); ptr++; } for( int l=0; l<10; l++ ) cout << a[l] << " "; cout << endl; ptr = &( a[5] ); *ptr = 100; for( int l=0; l<10; l++ ) cout << a[l] << " "; cout << endl; }