
Study C MCQ Questions and Answers on Preprocessor Directives. Easily attend technical job interviews with these Multiple Choice Questions.
Go through C Theory Notes on Preprocessor Directives before studying questions.
Only current directory will be searched for the specified file
Current Directory + Search Path Directories
You can specify multiple directories separated by Semicolons(;) under search path as below.
C:\turboc;C:\abc\libs;C:\def\bc\docs;
#IF macroname statement1; statement2; #ELSE statement3; statement4; #END
#IF macroname statement1; statement2; #ELSE statement3; statement4; #ENDIF
#IFDEF macroname statement1; statement2; #ELSE statement3; statement4; #ENDIF
#ifdef macroname statement1; statement2; #else statement3; statement4; #endif
C Conditional Compilation Commands IFDEF, ELSE and ENDIF should be in lower case letters only. If macroname exists or is defined, it is treated as true and TRUE block (IF) is executed. Otherwise, FALSE block (ELSE) is executed.
#define CVV 156 int main() { #ifdef CVV printf("CVV YES"); #else printf("CVV NO"); #endif return 0; }
Macro CVV is already defined.
#define CVV 156 int main() { #ifdef cvv printf("CVV YES"); #else printf("CVV NO"); #endif return 0; }
CVV is not equal to cvv. So cvv is not defined.
int main() { #ifdef CVV printf("CVV YES"); #else #define CVV 199 #endif printf("NEW CVV=%d",CVV); return 0; }
You can define a constant using Preprocessor directive even inside a main() function or any other function. So CVV is replaced by 199 everywhere it appears.
int main() { #ifndef CVV #define CVV 199 printf("CVV=%d", CVV); #else printf("CVV=%d", 188); #endif return 0; }
IFNDEF is executed when macroname is Not defined. IFNDEF is the opposite of IFDEF.
void show(); int main() { #ifndef CVV #define CVV 199 #endif show(); return 0; } void show() { printf("CVV=%d",CVV); }
Yes. CVV defined inside IFNDEF is available to outside functions also. So show() can display CVV.
int main() { #ifdef CVV #define CVV 199 #elif PVV printf("Inside ELIF"); #else printf("Inside ELSE"); #endif return 0; }
#ELIF is similar to ELSE IF condition.
#define BIRD 5 int main() { #ifdef BIRD printf("BIRD=5."); #else printf("UNKNOWN."); #endif #undef BIRD #define BIRD 10 printf("BIRD=%d",BIRD); return 0; }
Yes. You can use #define any where. Using #undef removes the definition of existing macro. No compiler error if macro is not found.
int main() { #undef BIRD printf("OKAY"); return 0; }
Macro BIRD is not define. So #undef tries to remove definition if any. No compiler error will come.
#pragma starup myfunction1
#pragma exit myfunction2
#pragma warn-rvl
void show1(); void show2(); #pragma startup show1 #pragma exit show2 int main() { printf("MAIN."); } void show1() { printf("START."); } void show2() { printf("END."); }
A Pragma works before compilation and after Preprocessing. It tells compiler to follow or ignore certain things.
RVL - Return Value missing. PAR - Parameter not used. RCH - Code not reachable.