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(size of(int));
if(NULL == x) return;
x = assignval(x, 10);
}
printf("%dn", *x);
free(x);
}
The code suffers from which one of the following problems: 2017 SET 1 ||MCQ || 1-mark
compiler error as the return of malloc is not typecast approximately
compiler error because the comparison should be made as x==NULL and not as shown
compiles successfully but execution may result in dangling pointer
compiles successfully but execution may result in memory leak
This question is part of this quiz :
GATE|| C Programming & Data Structure || Pyqs (2010 to 2025 ),GATE || C Programming || PYQS (2010 to 2025)