C Preprocessor

Q1:
Will the program compile successfully?
#include<stdio.h>

int main()
{
    #ifdef NOTE
        int a;
        a=10;
    #else
        int a;
        a=20;
    #endif
    printf("%d\n", a);
    return 0;
}

A Yes

B No

ANS:A - Yes

Yes, this program will compile and run successfully and prints 20. The macro #ifdef NOTE evaluates the given expression to 1. If satisfied it executes the #ifdef block statements. Here #ifdef condition fails because the Macro NOTE is nowhere declared. Hence the #else block gets executed, the variable a is declared and assigned a value of 20. printf("%d\n", a); It prints the value of variable a 20.



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.