Home / C Programming / C Preprocessor :: Discussion

Discussion :: C Preprocessor

  1. What will be the output of the program?

     #include
     #define MAX(a, b) (a > b ? a : b)  
    
     int main() 
     {   
         int x;  
         x = MAX(3+2, 2+7);     
         printf("%d\n", x);  
         return 0; 
      } 
    

  2. A.

    8

    B.

    9

    C.

    6

    D.

    5

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.

    Step 1 : int x; The variable x is declared as an integer type.

    Step 2 : x = MAX(3+2, 2+7); becomes,

    => x = (3+2 > 2+7 ? 3+2 : 2+7)

    => x = (5 > 9 ? 5 : 9)

    => x = 9

    Step 3 : printf("%d\n", x); It prints the value of variable x.

    Hence the output of the program is 9.


Be The First To Comment