Home / C Programming / C Preprocessor :: Discussion

Discussion :: C Preprocessor

  1. What will be the output of the program?

     #include
     #define FUN(i, j) i##j 
    
     int main() 
     {   
         int va1=10;  
         int va12=20;    
         printf("%d\n", FUN(va1, 2));        
         return 0; } 
    

     

  2. A.

    10

    B.

    20

    C.

    1020

    D.

    12

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The following program will make you understand about ## (macro concatenation) operator clearly.

     #include
     #define FUN(i, j) i##j 
    
     int main() 
     {    
          int First   = 10;   
          int Second  = 20;   
        
         char FirstSecond[] = "FresherGATE";  
        
         printf("%s\n", FUN(First, Second) );    
    
          return 0;
     }
     
      Output: 
      -------
      FresherGATE

    The preprocessor will replace FUN(First, Second) as FirstSecond.

    Therefore, the printf("%s\n", FUN(First, Second) ); statement will become as printf("%s\n", FirstSecond );

    Hence it prints IndiaBIX as output.

    Like the same, the line printf("%d\n", FUN(va1, 2)); given in the above question will become as printf("%d\n", va12 );.

    Therefore, it prints 20 as output.

     


Be The First To Comment