2,021 views
0 votes
0 votes

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);
}

(A) compiles successfully but execution may result in dangling pointer.

(B) compiles successfully but execution may result in memory leak.

(C) compiles and executes successfully 

It is the same question https://gateoverflow.in/118293/gate2017-1-13 but i want to know that adding * in if condition will result in dangling pointer or not?

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
2
Gaurav Nagar asked Aug 11, 2018
459 views
Hey guys, please let me know if there is any institute spot round still open in any nit or iiit?My gate score is 614 in obc category
0 votes
0 votes
0 answers
3
Gaurav Kadyan asked Nov 10, 2023
227 views
If a square matrix of order 100 has exactly 15 distinct eigen values, the degree of the minimal polynomial is (a) At least 15 (c) Always 15 (b) At most 15 (d) Exactly 100...