October 12, 2023
October 12, 2023
###### GATE 2021 CS-Set-2
October 12, 2023
October 12, 2023
 Question 216
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 = (struct Node *) malloc(sizeof(struct Node));

for (index = 1; index <= 3; index++) {

boxN = (struct Node *) malloc(sizeof(struct Node));

boxE->next = boxN;

boxN->value = index;

boxE = boxN; }

for (index = 0; index <= 3; index++) {

printf(“Value at index %d is %d\n”, index, head->value);

printf(“Value at index %d is %d\n”, index+1, head->value); } }

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

 A Upon execution, the program creates a linked-list of five nodes. B It dereferences an uninitialized pointer that may result in a run-time error. C Upon execution, the program goes into an infinite loop. D It has a missing return which will be reported as an error by the compiler.
Question 216 Explanation:

One node is created with value 0.

Loop i runs from 1 to 3. Hence total 4 nodes will be created.

0     →   1     → 2     → 3 → NULL

Head → Value from printf will generate an error.

Question 216 Explanation:

One node is created with value 0.

Loop i runs from 1 to 3. Hence total 4 nodes will be created.

0     →   1     → 2     → 3 → NULL

Head → Value from printf will generate an error.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7451068,"math_prob":0.95453674,"size":1395,"snap":"2023-40-2023-50","text_gpt3_token_len":414,"char_repetition_ratio":0.1279655,"word_repetition_ratio":0.4,"special_character_ratio":0.33046594,"punctuation_ratio":0.15625,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9648193,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-06T11:26:20Z\",\"WARC-Record-ID\":\"<urn:uuid:d829bb96-e2b0-4bb9-b297-781ee48ca6a6>\",\"Content-Length\":\"351801\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ed6b6650-5043-4ec3-9897-3b45539a9810>\",\"WARC-Concurrent-To\":\"<urn:uuid:d1385fa7-c8ee-4a23-8670-42a6005a263b>\",\"WARC-IP-Address\":\"191.96.144.134\",\"WARC-Target-URI\":\"https://solutionsadda.in/2023/10/12/data-structures-32/\",\"WARC-Payload-Digest\":\"sha1:EZ4XQ5XABMSI5T3DRRQDZ6HJFB2RKBGQ\",\"WARC-Block-Digest\":\"sha1:FWTYSHGONTTN6SK5LX6KPIXNPRRJI7EI\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100593.71_warc_CC-MAIN-20231206095331-20231206125331-00550.warc.gz\"}"}