GATE CS 2021 (Afternoon) — Question 45

Programming in CPointers, Multi-Dimensional Arrays, StructuresMCQ2 marks · −2/3 if wrongMedium

Consider the following ANSI C program:
c
1#include <stdio.h>
2#include <stdlib.h>
3struct Node{
4    int value;
5    struct Node *next;
6};
7int main( ) {
8    struct Node *boxE, *head, *boxN; int index = 0;
9    boxE = head = (struct Node *) malloc(sizeof(struct Node));
10    head -> value = index;
11    for (index = 1; index <= 3; index++) {
12        boxN = (struct Node *) malloc(sizeof(struct Node));
13        boxE -> next = boxN;
14        boxN -> value = index;
15        boxE = boxN; }
16    for (index = 0; index <= 3; index++) {
17        printf("Value at index %d is %d\n", index, head -> value);
18        head = head -> next;
19        printf("Value at index %d is %d\n", index+1, head -> value); } }
20
Which one of the statements below is correct about the program?
  1. A
    Upon execution, the program creates a linked-list of five nodes.
  2. B
    Upon execution, the program goes into an infinite loop.
  3. C
    It has a missing return which will be reported as an error by the compiler.
  4. D
    It dereferences an uninitialized pointer that may result in a run-time error.
Practise the full 2021-AN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAWhat rank do your marks get?GATE score, likely All-India Rank and qualifying marks for your category.
Practise more on Pointers, Multi-Dimensional Arrays, StructuresTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group