C Preprocessor Test 26) What will be the output of the below program?
The correct option is (a). Explanation: In program #ifdef, #else and #endif are preprocessor commands. If the macro DEF is defined by a #define statement, then the code immediately after #ifdef is compiled otherwise code between #else and #endif commands gets executed. Since, DEF has been defined, #ifdef DEF evaluates to true hence, square of 'j' is calculated and gets printed i.e 9. While defining the macro DEF, it is not compulsory to provide a expansion to the macro statement because in a program we are not using the value of macro expansion. Therefore the output of the program is square of j=9. The correct option is (b). Explanation: When the preprocessor sends the program for compilation IT, HRA and DA have been replaced by 0.1, 0.2 and 0.3 respectively. With the bas_sal set to 1000, the net salary is calculated as: The statement printf("Gross salary=%f\n", net_sal); prints the result. Therefore the output of Output: Gross salary=1400 The correct option is (b). Explanation: No, the header files may have any extension. It is not necessary that header file must have .h extension. The correct option is (c). Explanation: void *calloc(size_h nitems, size_h size): Function calloc() requires the double argument. void *malloc(size_h size): Function malloc() requires the single argument. For supporting the function- malloc() and calloc() stdlib.h header file is required. The correct option is (a). Explanation: Macro statement can be executed faster with no overhead of context switch because the code of macro gets expanded at the line of call. Therefore the above statement is true. |