#include <iostream>
using namespace std;
int main()
{
char * a = nullptr;
{
char * b = (char *) "hello";
a = b;
}
cout << a << endl; // prints hello
return 0;
}
I have the code above. I am having hard time understanding why the code doesnt crash. My reasoning is I expected a crash because I am passing pointer b to upper scope with pointer a and using it to cout. Since "hello" was created within b's scope and new keywords isnt used, I expected it to clean itself automatically like a variable in a scope. What am I thinking wrong??