edited by
170 views
3 votes
3 votes

What is the output of the following program?
$($Assume that the value returned by the malloc call is $1001.)$

#include<stdio.h>
#include<stdlib.h>
void fun(int **y);
int main()
{
   int *x = (int*)malloc(sizeof(int));
   *x = 132;
   fun(&x);
   printf("%d %u\n",*x,x);
}
void fun(int **y)
{
   int z=21;
   **y = z;
   printf("%u ",*y);
}
  1. $21$ $132$ $1001$
  2. $1001$ $21$ $1001$
  3. $1001$ garbage $1001$
  4. $21$ $21$ $132$
edited by

1 Answer

Best answer
2 votes
2 votes

$x$ is having value $1001$ after malloc.

*x = 132; -> [1001] = 132
void fun(int **y) -> *y = 1001
**y = z;     -> [1001] = 21

So, the correct answer is $(B).$

selected by
Answer:

Related questions