Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2017 Set 1
Questions

Q13

MCQ1 mark, −0.33Programming

Consider the following C code:

#include<stdio.h>
int *assignval (int *x, int val) {
    *x = val;
    return x;
}
void main () {
    int *x = malloc(sizeof(int));
    if (NULL == x) return;
    x = assignval (x,0);
    if (x) {
        x = (int *)malloc(sizeof(int));
        if (NULL == x) return;
        x = assignval (x,10);
    }
    printf("%d\n", *x);
    free(x);
}

The code suffers from which one of the following problems:

Sign in to save attempts.

The solution is hidden while you attempt this question. It opens once you check or show the answer.