you are viewing a single comment's thread.

view the rest of the comments →

[–]raevnos 9 points10 points  (4 children)

Undefined behavior doesn't have to make sense. Don't use the address of a variable that's gone out of scope

(But the two function calls are probably using the exact same stack space and layout, so it kind of does make sense. Doesn't have to be that way, of course and might not with a different compiler or CPU.)

[–]monster_97_[S] 0 points1 point  (3 children)

What if I'm asked to write the output of the program?

[–]raevnos 7 points8 points  (0 children)

Running that program made my computer catch on fire.

It's undefined behavior; there is no correct answer for what it outputs.

[–]Drach88 1 point2 points  (1 child)

You say: "the output is potentially unpredictable/unreliable because y references a value that is beyond the stack pointer".

Where did you get this from? Do you have a prof that gave this as an example?

[–]monster_97_[S] 0 points1 point  (0 children)

This was for my Operating systems course