Sail E0 Webinar
Question
What is the output of this C code?
int *f();
int main()
{
int *p = f();
printf("%d\n", *p);
}
int *f()
{
int *j = (int*)malloc(sizeof(int));
*j = 10;
return j;
}
Options:
A .  10
B .  Compile time error
C .  Segmentation fault/runtime crash since pointer to local variable is returned
D .  Undefined behaviour
Answer: Option A


None.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers