#include using namespace std; int main() { // 8.23 (a) cout << "8.23 (a)" << endl; int *number; cout << number << endl; // There is no compiler error, but we have the following two problems... // 1. number is a pointer that is uninitialized, so outputting it will // give garbage. // 2. We're outputing a memory location, not an integer. // (It might be that's what we want, who knows.) // 8.23 (b) cout << endl << endl << "8.23 (b)" << endl; double *realPtr; long *integerPtr; integerPtr = realPtr; // Compiler Error: cannot assign pointers to // different types to each other (without casting) // 8.23 (c) cout << endl << endl << "8.23 (c)" << endl; int *x, y; x = y; // Compiler Error: x and y are of different types! // 8.23 (d) cout << endl << endl << "8.23 (d)" << endl; char s[] = "this is a character array"; for ( ; *s != '\0'; s++) // Compiler Error: 's' is a const pointer! cout << *s << ' '; // 8.23 (e) cout << endl << endl << "8.23 (e)" << endl; short *numPtr, result; void *genericPtr = numPtr; result = *genericPtr + 7; // Compiler Error: cannot deref a void pointer // for anything meaningful! (needs a cast) // 8.23 (f) cout << endl << endl << "8.23 (f)" << endl; double xF = 19.34; double xFPtr = &xF; // Compiler Error: xFPtr is of type int, not int* cout << xFPtr << endl; // and thus we cannot assign it a memory location // 8.23 (g) cout << endl << endl << "8.23 (g)" << endl; char *sG; cout << sG << endl; // There is no compiler error, but we have the following problems... // 1. We're outputing an unintialized pointer, so we'll get garbage. // 2. Character pointers (char*) are almost always interpretted as // strings (C-Style strings), so when one cout's a char*, it actually // tries to dereference that pointer and output the sequence of // characters starting there. Since this is uninitialized, this // will just output memory locations, byte-by-bye, until a null // character is found. return 0; }