did you try it? here's some sample code:
Code:
#include<iostream>
struct test
{
int i;
};
int main()
{
{
test*f=new test;
f->i=50;
std::cout<<f->i<<std::endl;
delete test;
}
std::cout<<f->i<<std::endl; //line 16
return 0;
}
and this is what you get:
Code:
jshao@MCP ~/Programming/C++ $ g++ test.cpp -Wall -o test.exe
test.cpp: In function `int main()':
test.cpp:16: error: `f' undeclared (first use this function)
test.cpp:16: error: (Each undeclared identifier is reported only once for each
function it appears in.)
basically, everything follows the rules of scope... you don't need to set the pointer to null because it doesn't exist after the code leaves the pointer's scope. you still need to free up the memory though--just because there's nothing holding it's location doesn't mean it's not there.