Home / C Programming / C Preprocessor :: Discussion

Discussion :: C Preprocessor

  1. What will be the output of the program?

     #include
     #define FUN(arg) do\                    
                      {\                       
                        if(arg)\                         
            printf("FresherGATE...", "\n");\                
                 }while(--i)  
     int main()
     {    
         int i=2;    
         FUN(i3);    
         return 0;
     } 
    

  2. A.

    FresherGATE...
    FresherGATE...
    FresherGATE

    B.

    FresherGATE... FresherGATE...

    C.

    Error: cannot use control instructions in macro

    D.

    No output

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The macro FUN(arg) prints the statement "IndiaBIX..." untill the while condition is satisfied.

    Step 1: int i=2; The variable i is declared as an integer type and initialized to 2.

    Step 2: FUN(i becomes,

     

    do {     if(2 3)     printf("IndiaBIX...", "\n"); }while(--2) 

     

    After the 2 while loops the value of i becomes '0'(zero). Hence the while loop breaks.

    Hence the output of the program is "IndiaBIX... IndiaBIX..."


Be The First To Comment