MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Give syntax to create a node for Single linked list?
A
newnode=(struct node *)malloc(sizeof(struct node*));
B
newnode=(struct node )malloc(sizeof(struct node));
C
newnode=(struct node *)malloc(sizeof(struct node));
D
newnode=(struct node )malloc(sizeof(struct node*));
Explanation: 

Detailed explanation-1: -struct Node int data; struct Node *next; ; The function insert() inserts the data into the beginning of the linked list. It creates a new node and inserts the number in the data field of the new node. Then the new node points to the head.

Detailed explanation-2: -In C language, a linked list can be implemented using structure and pointers . struct LinkedList int data; struct LinkedList *next; ; The above definition is used to create every node in the list. The data field stores the element and the next is a pointer to store the address of the next node.

There is 1 question to complete.