ある関数がスタック変数のアドレスを返すと、プログラムが意図しない動作(通常はクラッシュ)を引き起こす。
ローカル変数はスタック上に割り当てられるため、プログラムがローカル変数へのポインタを返すとき、それはスタック・アドレスを返すことになる。後続の関数呼び出しは、この同じスタック・アドレ スを再利用する可能性が高く、それによってポインタの値が上書きされます。ポインタの値が予期せず変更されるのは、せいぜいこの程度である。多くの場合、次にポインタが再参照されたときにプログラムがクラッシュします。
A function returns the address of a stack variable, which will cause unintended program behavior, typically in the form of a crash.
Because local variables are allocated on the stack, when a program returns a pointer to a local variable, it is returning a stack address. A subsequent function call is likely to re-use this same stack address, thereby overwriting the value of the pointer, which no longer corresponds to the same variable since a function's stack frame is invalidated when it returns. At best this will cause the value of the pointer to change unexpectedly. In many cases it causes the program to crash the next time the pointer is dereferenced.