Govt. Exams
Entrance Exams
#if evaluates constant expressions for conditional compilation. #ifdef checks if a macro is defined, #define creates macros, and #pragma provides compiler-specific directives.
The preprocessor is a text processing tool that processes source code before actual compilation, handling directives like #define, #include, and macros.
defined(MACRO) is used in #if and #elif directives to test if a macro is defined. Example: #if defined(DEBUG) ... #endif. It's equivalent to #ifdef but can be used in expressions with logical operators like && and ||.
#if 0...#endif is used to disable code during preprocessing. The enclosed code is skipped entirely and doesn't appear in the compiled output. This is more efficient than C-style comments for large blocks and maintains nested comment compatibility.
#include <file.h> searches in standard system include directories. #include "file.h" searches in the current working directory first, then system directories. This allows you to override system headers with local versions.
assert.h contains the assert() macro which is useful for debugging. It tests a condition and aborts the program if the condition is false. This macro is only active when NDEBUG is not defined.
Both options A and B are valid. The ## operator pastes two tokens together. Whitespace around ## doesn't matter. #define CONCAT(a,b) a##b could be used as CONCAT(var, 1) to create var1.
#undef cancels the definition of a macro, allowing it to be redefined later. After #undef, the macro name becomes undefined.
NULL is defined in multiple headers including <stdio.h>, <stdlib.h>, <stddef.h>, and others. Any of these can be included to use NULL.
__LINE__ expands to the current line number. __FILE__ gives filename, __DATE__ gives compilation date, __STDC__ indicates C standard compliance.