Question
#include<stdio.h>
#define MIN(x, y) (x 0)
printf("%d\n", z);
return 0;
}
What will be the output of the program?
#include<stdio.h>
#define MIN(x, y) (x 0)
printf("%d\n", z);
return 0;
}
Answer: Option A
Was this answer helpful ?
The macro MIN(x, y) (x<y)? x : y; returns the smallest value from the given two numbers.
Step 1: int x=3, y=4, z; The variable x, y, z are declared as an integer type and the variable
x, y are initialized to value 3, 4 respectively.
Step 2: z = MIN(x+y/2, y-1); becomes,
=> z = (x+y/2 < y-1)? x+y/2 : y - 1;
=> z = (3+4/2 < 4-1)? 3+4/2 : 4 - 1;
=> z = (3+2 < 4-1)? 3+2 : 4 - 1;
=> z = (5 < 3)? 5 : 3;
The macro return the number 3 and it is stored in the variable z.
Step 3: if(z > 0) becomes if(3 > 0) here the if condition is satisfied. It executes the ifblock statements.
Step 4: printf("%d`setminus`n", z);. It prints the value of variable z.
Hence the output of the program is 3
Was this answer helpful ?
Submit Solution