vendredi 25 décembre 2015

new KeyWord c++ (Assistance Required)

  1. I have following code that work 100 percent fine. I am also aware, what is actually going behind the scene. how "new" works in that case.

    struct ABC{
        int data = 1234;
    };
    ABC *obj = new ABC;
    cout << "obj->data";
    
    
  2. The following code does not work it compiles correctly then crashed. no syntax or compile error.

    struct ABC{
        int data = 1234;
    };
    ABC *obj; // please explain??
    cout << "obj->data";
    
    
  3. Following code also works fine and simple one.

    struct ABC{
        int data = 1234;
    };
    ABC *obj, myobj;
    myObj = &obj;
    cout << "obj->data";
    
    

I am also aware, hows 3rd one is working. Please explain, why 2nd one is not working. Sorry for not making main() procedure.

Aucun commentaire:

Enregistrer un commentaire