#include int* f(int x) { int *pp; if ( x ) { int y = 3; pp = &y; // ok so far } //y = 4; // does not compile // pp is now dangling! *pp = 7; // Wrong!!! But may not crash!! Sneaky bug return pp; // Super wrong!! } void g(int *p) { int a = 3; int b = 4; *p = 123; printf("The value of p is %d\n", *p); // *** Check this out, we have overwritten memory! *** // *** Very common bug. Watch-out for this type of errors *** // Note: this example may not work on all systems // It depends where the local variables appear in the // activation record printf("The value of a is %d\n", a); printf("The value of b is %d\n", b); } int main() { int *p; p = f(3); // p is now dangling too *p = 5; // Wrong! but can also be a silent problem printf("The value is %d\n", *p); // And now the fun part! g(p); return 0; }