Whats the error in this code?

// TAB – The Ampersand Bug function
// Returns a pointer to an int
int* TAB() {
int temp;
return(&temp); // return a pointer to the local int
}
void Victim() {
int* ptr;
ptr = TAB();
*ptr = 42; // Runtime error! The pointee was local to TAB
}

Hey Divyam, that’s because TAB() is returning the address of temp which was TAB()'s local variable, as TAB() is fully executed all its local variables are also destroyed, so you can’t assign the address of a local variable that’s already destroyed to some other variable.