Home / C Programming / C Preprocessor :: Discussion

Discussion :: C Preprocessor

  1. What will be the output of the program?

     #include'
     #define MAN(x, y) ((x)>(y)) ? (x):(y);
    
      int main() 
     {   
         int i=10, j=5, k=0;  
         k = MAN(++i, j++);     
         printf("%d, %d, %d\n", i, j, k);     
         return 0; 
    } 
    

  2. A.

    12, 6, 12

    B.

    11, 5, 11

    C.

    11, 5, Garbage

    D.

    12, 6, Garbage

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    The macro MAN(x, y) ((x)>(y)) ? (x):(y); returns the biggest number of given two numbers.

    Step 1: int i=10, j=5, k=0; The variable i, j, k are declared as an integer type and initialized to value 10, 5, 0 respectively.

    Step 2: k = MAN(++i, j++); becomes,

    => k = ((++i)>(j++)) ? (++i):(j++);

    => k = ((11)>(5)) ? (12):(6);

    => k = 12

    Step 3: printf("%d, %d, %d\n", i, j, k); It prints the variable i, j, k.

    In the above macro step 2 the variable i value is increemented by 2 and variable j value is increemented by 1.

    Hence the output of the program is 12, 6, 12


Be The First To Comment