#include<iostream>
int* function() {
    int a = 2;
    return &a;
}
int main() {
    int* b = function();
    *b = 3;
    return 0;
}
I was trying to run this program, but this is supposed to give me an error because a should be deleted after leaving the function. However, I received no error in Visual Studio 2022. a is not even a static variable, nor is b constant.
I tried to copy and paste this code in different compilers to see if the lecture was wrong, but I recieved
main.cpp:4:16: warning: address of local variable ‘a’ returned [-Wreturn-local-addr]
like what it is supposed to be.
 
     
    