Govt. Exams
Entrance Exams
#ifdef checks if a macro is defined, #ifndef checks if it's not defined. Both are used for conditional compilation based on macro definition status.
#allocate is not a valid preprocessor directive. Valid directives include #include, #define, #pragma, #ifdef, #ifndef, #if, #else, #elif, #endif, #error, #undef.
The preprocessor is a separate program that processes source code before the compiler. It handles directives like #include, #define, and #ifdef.
#undef is used to remove the definition of a macro so it cannot be used in subsequent code.
#define MAX(a,b) (a>b?a:b)
printf("%d", MAX(10, 5));
The macro expands to (10>5?10:5) which evaluates to 10 since the condition is true.
#define SQUARE(x) ((x)*(x))
This is a function-like macro that takes parameter x and expands to ((x)*(x)). The parentheses around x prevent operator precedence issues.
#include <filename> is used for standard library files (searched in standard paths). #include "filename" is used for user-defined header files (searched in current directory first).
#define MAX 5
int arr[MAX];
The preprocessor replaces MAX with 5, creating an array of size 5. This is a valid use of macro expansion.
#declare is not a valid preprocessor directive. Valid directives include #define, #include, #pragma, #ifdef, #endif, #if, #else, etc.