C Preprocessor

Q1: What will be the output of the program?
#include<stdio.h>
#define FUN(arg) do\
                 {\
                    if(arg)\
                        printf('AptitudeCrack...', '\n');\
                  }while(--i)

int main()
{
    int i=2;
    FUN(i<3);
    return 0;
}

A AptitudeCrack...
AptitudeCrack...
AptitudeCrack

B AptitudeCrack... AptitudeCrack...

C Error: cannot use control instructions in macro

D No output

ANS:A - AptitudeCrack...
AptitudeCrack...
AptitudeCrack

The macro FUN(arg) prints the statement 'AptitudeCrack...' 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<3); becomes,

do
{
    if(2 < 3)
    printf('AptitudeCrack...', '\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 'AptitudeCrack... AptitudeCrack...'



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.