mercredi 13 novembre 2019

POINTER TO STACK-MEMORY

class object
{
public:
    object(){}
    ~object(){}
};

int main()
{
    object *p = NULL;
    {
         object a;
         p = &a;
         if(p){
             cout << "not NULL\n";
         }
         else{
             cout << "NULL ptr\n";
         }
    }
    if(p){
        cout << "not NULL\n";
    }
    else{
        cout << "NULL ptr\n";
    }
    return 1;
}

result:

not NULLnot NULL

i don't know why this result, i think it is "not NULL and NULL". when object'destructor was called, then p pointer to? how does stack memory work?

Aucun commentaire:

Enregistrer un commentaire