...
| Code Block | ||
|---|---|---|
| ||
char const *p;
void dont_do_this() {
char const *str[] = "This will change";
p = str; /* dangerous */
/* ... */
}
void innocuous() {
char const *str[] = "Surprise, surprise";
}
/* ... */
dont_do_this();
innocuous();
/* now, it is likely that p is pointing to "Surprise, surprise" */
|
...
| Code Block | ||
|---|---|---|
| ||
void this_is_OK() {
char const *str[] = "Everything OK";
char const *p = str;
/* ... */
}
/* pointer p is now inaccessible outside the scope of string str */
|
...