In this code, I reference the local variable b
even though it is out of scope. But I do it from within the same function so it's probably still on the stack, right? I ran the program and it worked but I'd like to know if it's guaranteed to work on all implementations.
#include <iostream>
void main()
{
int* a;
{
int b = 5;
a = &b;
}
std::cout << *a;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…