dimanche 17 mai 2020

Without allocating memory How I am able to create assign values to variables?

struct node
{
    int data;
    node* next;
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);



    node* temp;
    temp->data=5;
    temp->next=0;
    cout<<temp->data;


    return 0;
}

Without allocating memory in heap why this code is working. If its correct why we allocate memory in heap to create nodes in linked lists.

Aucun commentaire:

Enregistrer un commentaire