/* Lecture #5 Demo * * Bad Pointer * * The first loop uses a character pointer to step through a string * to the null terminator at the end. * The second loop uses an integer pointer to scan the region of * memory where the local variables are located. */ #include int main() { char s[] = "Hello World.\n"; char *t = s; do { printf("(0x%08X): %c %3d 0x%X\n", t, *t, *t, *t); } while (*t++); printf("\n\n"); int *badptr = NULL; /* A type cast is needed for this assignment to avoid a */ /* warning of "incompatible pointer assignment". */ badptr = (int *)s; do { printf("(0x%08X) : %12d 0x%08X\n", badptr, *badptr, *badptr); } while (*badptr++); /* What (if anything) causes this loop to terminate? */ }