Dee Khan February 2016

Self structure and pointers in linklist

I have few confusion in understanding the linked list. Here is my full code.

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



main()
{
head =new node;
head -> data=5;
head -> next=NULL;

node *ptr=new node;
ptr -> data=6;
head -> next=ptr;
ptr -> next= NULL;

}

1) The self defined struct node pointer in the structure is made to hold the address of structure of same type, according to this link and what will be the size of node *next?

2) when we make 2nd node ptr, in the linked list we assign the address of 2nd node to the address part of 1st node, so we can assign the & sign how can we do that with head -> next=ptr;

I am sorry for ask too basic things but I think I mixed concepts of pointers. Please help me to understand that

Answers


GTKM February 2016

Next is a pointer, so it has the size of a pointer, which means 8B in a 64-bit architecture. Of course, you can see this with a simple sizeof(struct node *).

Post Status

Asked in February 2016
Viewed 1,526 times
Voted 6
Answered 1 times

Search




Leave an answer