Govt. Exams
Entrance Exams
The ## operator concatenates two tokens into one. For example, #define CONCAT(a,b) a##b creates CONCAT(hello, world) → helloworld.
#define PI 3.14
int main() { printf("%f", PI); return 0; }
PI is replaced by 3.14 during preprocessing. When printed with %f format specifier, it displays as 3.140000 (default 6 decimal places).
Option A uses #ifdef to check if DEBUG is defined, which is correct for conditional compilation. Option B would check if DEBUG has a non-zero value (expression-based). Options C and D have invalid syntax.
NULL is defined in multiple standard headers including <stdio.h>, <stdlib.h>, <stddef.h>, <string.h>, and others. Any of these can be included to use NULL.
#define PI 3.14
#undef PI
#define PI 3.14159
What is the value of PI after execution?
#undef removes the previous definition of PI. The subsequent #define redefines PI as 3.14159. This is valid C syntax and the final value of PI is 3.14159.
The angle bracket version searches in standard system directories first, while quoted version searches in the current/local directory first. Both statements B and C correctly describe this distinction.
#define is used to create macro definitions and constants at compile time. #const, #constant, and #fixed are not valid preprocessor directives in C.
Standard library headers like stdio.h, stdlib.h, string.h are included using angle brackets #include <filename>.
Both #ifndef and #if !defined(MACRO) are equivalent and check if a macro is not defined. #ifndef is simpler syntax for this specific case.
Preprocessor directives (starting with #) are processed before the actual compilation by a separate preprocessor tool. They perform text substitution and conditional compilation.