C Preprocessor Test 416) What will be the output of the below program?
The correct option is (b). Explanation:
During preprocessing, the macro MYFILE gets replaced with <stdio.h>, then program is compiled and executed as shown below: Therefore the output of program is: Hello Welcome to javatpoint 17) Will it be result in to an error if a header file is included twice in a program?
The correct option is (c). Explanation: In GCC compilers and Turbo C the compiler would take care of these problems and it generates no error. In other compilers the error may occur. Unless the header file has taken care for ensure that if already included then it doesn't get included again. Therefore an error in a program due to use of header file twice in a program is compiler dependent. 18) The preprocessor can trap simple error like nested comments, mismatch of braces or missing declarations.
The correct option is (b). Explanation: The statement is false because the preprocessor cannot trap the errors; it only replaces the macro with the given expression. The compiler is used for detecting an error in a program. 19) In every C program there is at least one preprocessor directive.
The correct option is (b). Explanation: The statement is false because the preprocessor directive is not compulsory in any C program. We can also develop a program in C language without using any preprocessor directive. 20) What will be the output of the below program?
The correct option is (d). Explanation: The macro MAX(x, y) (x > y ? x : y) returns the biggest value of the given two numbers. Step 1: int a; The variable 'a' is declared as an integer type. Step 2: a = MAX(3+1, 2+4); becomes, => a = (3+1 > 2+4 ? 3+1 : 2+4) => a = (4 > 6 ? 4 : 6) => a = 6 Step 3: printf("%d\n", a); It prints the value of variable 'a'. Hence the output of the program is 6. Next Topic# |