Is the following code valid
int main(){
int * a = 0;
if ( !a ) {
int b[500];
a = b;
}
//do something with a,
//has the array a is
//pointing too gone out
//of scope and garbage
//or is it still fine?
}
No it is not, b has gone out of scope, accessing it (through the pointer) is undefined behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With