C Preprocessor

Q1: What will be the output of the program?
#include<stdio.h>
#define MIN(x, y) (x<y)? x : y;
int main()
{
    int x=3, y=4, z;
    z = MIN(x+y/2, y-1);
    if(z > 0)
        printf('%d\n', z);
    return 0;
}

A 3

B 4

C 0

D No output

ANS:A - 3

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 if block statements. Step 4: printf('%d\n', z);. It prints the value of variable z. Hence the output of the program is 3



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.