C Preprocessor

Q1: What will be the output of the program?
#include<stdio.h>
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)

int main()
{
    int x;
    x = MAX(3+2, 2+7, 3+7);
    printf('%d\n', x);
    return 0;
}

A 3+7

B 5

C 9

D 10

ANS:A - 5

The macro MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) returns the biggest of given three numbers. Step 1: int x; The variable x is declared as an integer type. Step 2: x = MAX(3+2, 2+7, 3+7); becomes, => x = (3+2 >2+7 ? 3+2 > 3+7 ? 3+2 : 3+7: 2+7 > 3+7 ? 2+7 : 3+7) => x = (5 >9 ? (5 > 10 ? 5 : 10): (9 > 10 ? 9 : 10) ) => x = (5 >9 ? (10): (10) ) => x = 10 Step 3: printf('%d\n', x); It prints the value of 'x'. Hence the output of the program is '10'.



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.