Code:
char* foo;
char* bar;
foo = malloc(2);
bar = malloc(2);
free(foo);
foo[0]='\0'; // this is wrong
foo = bar;//Making it point elsewhere
foo[0]='\0'; // safe again
Kurt
Edit:
I think there is nothing mysterious about the use of pointers. I think that it is obvoious that you must not do what I have marked as wrong in the example above.
Trouble is that you cannot do much to prevent such mistakes. ( other than being careful ).
Another example of what could go wrong is:
Code:
char* foo;
char* bar;
foo = malloc(2);
bar = malloc(2);
foo = bar; // Making it point elsewhere, original foo is lost now
free(foo);
bar[0]='\0'; // wrong bar was freed via foo