Hi ,
Can anybody explain me the strange behaviour of structure pointer......
I have the following code....
Code:
//ABC.cpp
struct ABC
{
int age;
long salary;
char* name;
};
class file
{
ABC* read(char*);
void write(ABC*);
};
ABC* file::read(char* namePass)
{
ABC *a =new ABC;
a->name="JOHN";
if(namePass==a->name)
{
a->age=12;
a->salary=34555;
}
else{ return NULL;}
return a;
};
// The above function is called as follow in another CPP file......
ABC *abc;
file *m_file;
abc->read(name);
if(!abc)
{
ABC *abc =new ABC;
abc->name="JOHN";
abc->age="23";
abc->salary="45555";
m_file->write(abc);
}
delete abc;
cout<<abc->age; // IT's returning valid value. 23
I want to know that when I have deleted the pointer abc.....then why should it giving the correct value.......???????
Please conside the case when it read function returns NULL......
Thanks