ExamTray App is now Available on Google Play EXAMTRAY android app link

 

C MCQ Questions and Answers on Preprocessor Directives 2

Image
C MCQ Questions and Answers

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.



1) What does #include stdio.h does in c language.?
A) It includes stdio.h into existing C program.
B) #include increases the size of C program by including the specified file contents like functions, constants etc.
C) #include includes specified file before compilation.
D) All the above
Answer [=]
D
2) What is the abbreviation of C STDIO in stdio.h.?
A) Standard Input Output
B) String Terminating Operations Input Output
C) Store Input Output
D) None of the above
Answer [=]
A
3) Choose a correct statement about #include<stdio.h>.?
A) A file named stdio.h will be searched in all directories and included if found
B) A file named stdio.h will be searched in current directory and included if found
C) A file named stdio.h will be searched in current directory and pre configured list of directories in search path and included if found
D) None of the above
Answer [=]
B
Explanation:

Only current directory will be searched for the specified file

4) Choose a correct C statement about #include"
A) A file named stdio.h will be searched in all directories and included if found
B) A file named stdio.h will be searched in current directory and included if found
C) A file named stdio.h will be searched in current directory and pre configured list of directories in search path and included if found
D) None of the above
Answer [=]
C
Explanation:

Current Directory + Search Path Directories

5) In Turbo C, Search Path of Directories for #Include is mentioned under the option.?
A) Include Directories
B) Exclude Directories
C) Add Directories
D) Extra Directories
Answer [=]
A
Explanation:

You can specify multiple directories separated by Semicolons(;) under search path as below.

C:\turboc;C:\abc\libs;C:\def\bc\docs;
6) Choose a correct form of using C Conditional Compilation commands IF ELSE .?
A) #IF macroname statement1; statement2; #ELSE statement3; statement4; #END
B) #IF macroname statement1; statement2; #ELSE statement3; statement4; #ENDIF
C) #IFDEF macroname statement1; statement2; #ELSE statement3; statement4; #ENDIF
D) #ifdef macroname statement1; statement2; #else statement3; statement4; #endif
Answer [=]
D
Explanation:

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.

7) What is the output of C program with conditional compilation commands.? #define CVV 156 int main() { #ifdef CVV printf("CVV YES"); #else printf("CVV NO"); #endif return 0; }
A) 156
B) printf("CVV YES");
C) CVV YES
D) CVV NO
Answer [=]
C
Explanation:

Macro CVV is already defined.

8) What is the output of C program with conditional compilation commands.?#define CVV 156 int main() { #ifdef cvv printf("CVV YES"); #else printf("CVV NO"); #endif return 0; }
A) printf("CVV YES");
B) CVV YES
C) CVV NO
D) Compiler error
Answer [=]
C
Explanation:

CVV is not equal to cvv. So cvv is not defined.

9) What is the output of C program with preprocessor directives.? int main() { #ifdef CVV printf("CVV YES"); #else #define CVV 199 #endif printf("NEW CVV=%d",CVV); return 0; }
A) CVV 199
B) printf("CVV YES");
C) CVV YES
D) NEW CVV=199
Answer [=]
D
Explanation:

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.

10) What is the output of C program.? int main() { #ifndef CVV #define CVV 199 printf("CVV=%d", CVV); #else printf("CVV=%d", 188); #endif return 0; }
A) CVV=188
B) CVV=0
C) CVV=199
D) Compiler error
Answer [=]
C
Explanation:

IFNDEF is executed when macroname is Not defined. IFNDEF is the opposite of IFDEF.

11) What is the output of C program with Preprocessor directives.? void show(); int main() { #ifndef CVV #define CVV 199 #endif show(); return 0; } void show() { printf("CVV=%d",CVV); }
A) No output
B) CVV=0
C) CVV=199
D) Compiler error
Answer [=]
C
Explanation:

Yes. CVV defined inside IFNDEF is available to outside functions also. So show() can display CVV.

12) What is the output of C program with preprocessor directives.? int main() { #ifdef CVV #define CVV 199 #elif PVV printf("Inside ELIF"); #else printf("Inside ELSE"); #endif return 0; }
A) Inside ELIF
B) Inside ELSE
C) No output
D) Compiler error
Answer [=]
B
Explanation:

#ELIF is similar to ELSE IF condition.

13) What is the output of C program with #undef.? #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; }
A) BIRD=5.BIRD=5
B) BIRD=10.BIRD=10
C) BIRD=5.BIRD=10
D) Compiler error
Answer [=]
C
Explanation:

Yes. You can use #define any where. Using #undef removes the definition of existing macro. No compiler error if macro is not found.

14) What is the output of C program with #undef.? int main() { #undef BIRD printf("OKAY"); return 0; }
A) OKAY
B) Compiler error
C) BIRDOKAY
D) None of the above
Answer [=]
A
Explanation:

Macro BIRD is not define. So #undef tries to remove definition if any. No compiler error will come.

15) What is a Pragma in C language.?
A) A Pragma may be an instruction to build tool to process or generate comments
B) A Pragma may be an instruction to compiler to execute specific functions at specific times say startup or exit of program.
C) A pragma may be an instruction to tell compiler to ignore certain warnings.
D) All the above
Answer [=]
D
Explanation:

#pragma starup myfunction1

#pragma exit myfunction2

#pragma warn-rvl

16) What is the C Pragma directive or command to execute a particular function at startup of program.?
A) #pragma start function1
B) #pragma statup function1
C) #pragma startnow function1
D) #prama startup function1
Answer [=]
B
17) What is the output of C program with Pragma.? void show1(); void show2(); #pragma startup show1 #pragma exit show2 int main() { printf("MAIN."); } void show1() { printf("START."); } void show2() { printf("END."); }
A) MAIN.START.END.
B) START.MAIN.END
C) START.END.MAIN
D) END.START.MAIN
Answer [=]
B
18) At what stage of building a C program does Pragma work.?
A) Before Compilation
B) After compilation
C) After Linking
D) None of the above
Answer [=]
A
Explanation:

A Pragma works before compilation and after Preprocessing. It tells compiler to follow or ignore certain things.

19) Choose a correct implementation of C Pragma Warning.?
A) #pragma warn -par
B) #pragma warn -rch
C) #pragma warn -rvl
D) All the above
Answer [=]
D
Explanation:

RVL - Return Value missing. PAR - Parameter not used. RCH - Code not reachable.

20) Choose a correct statement about C Macro.?
A) A Macro name can be in lower or upper case.
B) A Macro can be nested. It can use another macro as part of its implementation. #define CVV 2*OLDCVV. Here OLDCVV is another macro defined prior to Macro CVV.
C) Control is not passed to Macro as it is like just a dummy String(eg. CVV) Replacement technique with implementation (Macro Expansion part)
D) All the above
Answer [=]
D