C-Programming-data-structure || 2017 SET 1 ||MCQ || 1-mark || Module 1: C Programming

Last Updated :
Discuss
Comments

Consider the following C code:

C
#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

Share your thoughts in the comments
Article Tags :