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?