int* func() {
int c = 5;
return &c;
}
int main() {
int* s = func();
std::cout << *(s) << "\n";
*(s) = 1000;
std::cout << *(s);
}
On my visual studio compiler this code works fine and giving me 5 and 1000. And I also checked it with 3 variables and discovered, that function keeps only one variable in memory for the lifetime of all program. So if anyone interested please check this code on your visual studio c++ 17 compiler. I just interested is it my compiler doesnt work fine or this is typical problem. Also in another compiler this code returns error as it must be.