Question 122Asked in BEL PE Computer Science, 20 Dec 2025 (5:00 PM)

Consider the following C program that creates and traverses a singly linked list. What will be the output?

Consider the following C program that creates and traverses a singly linked list. What will be the output? #include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node *next; }; int main() { struct Node *head, *second, *third; head = (struct Node*)malloc(sizeof(struct Node)); second = (struct Node*)malloc(sizeof(struct Node)); third = (struct Node*)malloc(sizeof(struct Node)); head->data = 5; head->next = second; second->data = 10; second->next = third; third->data = 15; third->next = NULL; struct Node *ptr = head; while (ptr != NULL) { printf("%d ", ptr->data); ptr = ptr->next->next; } return 0; }
  1. A5 15
  2. B5 10 15
  3. C5 10
  4. DSegmentation fault (runtime error)
Show answerHide answer

Correct answer: (D) Segmentation fault (runtime error)

From BEL PE Computer Science PYQ, 20 Dec 2025 (5:00 PM)

This is question 122 of BEL PE Computer Science PYQ, 20 Dec 2025 (5:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.