Sounds right to me. To add to it, I also am far from sure (C goes back some decades in terms of practical use and experience for me) but it could well be that i and p are both living on a stack, and that the embracing scope of the function main() in this instance remains on the stack until that function returns. Seen another way it may be undefined behaviour but also slightly better than mere chance that you experience it in this example (i.e. that it's reliably reproducible) in part because it's a a very terse example but also possibly because the anonymous scope you'd declared i in may (being anonymous) have the stack life that the enclosing function's scope does. That is assuming C puts variables on the stack at all .... my memory on implementation details is, alas, rather distant ;-)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Sounds right to me. To add to it, I also am far from sure (C goes back some decades in terms of practical use and experience for me) but it could well be that
i
andp
are both living on a stack, and that the embracing scope of the functionmain()
in this instance remains on the stack until that function returns. Seen another way it may be undefined behaviour but also slightly better than mere chance that you experience it in this example (i.e. that it's reliably reproducible) in part because it's a a very terse example but also possibly because the anonymous scope you'd declaredi
in may (being anonymous) have the stack life that the enclosing function's scope does. That is assuming C puts variables on the stack at all .... my memory on implementation details is, alas, rather distant ;-)