CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following ANSI C program:

#include <stdio.h>
#include <stdlib.h>
struct Node
{
int value;
struct Node *next;
};
int main( )
{
struct Node *boxE, *head, *boxN;
int index = 0;
boxE = head = (strcut Node *) malloc(sizeof (struct Node));
head value = index;
for (index = 1; index <=3; index++){
boxN = (struct Node *) malloc (sizeof (struct Node));
boxE next = boxN;
boxN value = index;
boxE = box N;}
for (index = 0; index <= 3; index ++)
{
printf("Value at index %d is %d\n", index, head value);
head = head next;
printf("Value at index %d is %d\n", index + 1, head value);
}
}

Which one of the statements below is correct about the program?

A
It has a missing return which will be reported as an error b the compiler.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
It dereferences an uninitialized pointer that may result in a run-time error.
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
Upon execution, the program goes into an infinite loop.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Upon execution, the program creates a linked-list of five nodes
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B It dereferences an uninitialized pointer that may result in a run-time error.
As we can in the loop, i runs from 1 to 3.

So, four nodes will be created because one node is already created with value 0.


When index = 3, then head value = 3
Head = Head Next (Now head will point to NULL)
Head Value [which is in print. So it will generate Run time Error]

So, option (c) is correct.

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Square Root of a Complex Number
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon