250+ TOP MCQs on File Inclusion and Answers

C programming quiz on “File Inclusion” along with answers, explanations and/or solutions:

1. What is the sequence for preprocessor to look for the file within <>?
a) The predefined location then the current directory
b) The current directory then the predefined location
c) The predefined location only
d) The current directory location

Answer: a
Clarification: <> first searches the predefined location for the specified file and then the current directory.

2. Which directory the compiler first looks for the file when using #include?
a) Current directory where program is saved
b) C:COMPILERINCLUDE
c) S:SOURCEHEADERS
d) Both C:COMPILERINCLUDE and S:SOURCEHEADERS simultaneously

Answer: b
Clarification: None.

3. What would happen if you create a file stdio.h and use #include “stdio.h”?
a) The predefined library file will be selected
b) The user-defined library file will be selected
c) Both the files will be included
d) The compiler won’t accept the program

Answer: b
Clarification: None.

4. How is search done in #include and #include “somelibrary.h” according to C standard?
a) When former is used, current directory is searched and when latter is used, standard directory is searched
b) When former is used, standard directory is searched and when latter is used, current directory is searched
c) When former is used, search is done in implementation defined manner and when latter is used, current directory is searched
d) For both, search for ‘somelibrary’ is done in implementation-defined places

Answer: d
Clarification: None.

5. How is search done in #include and #include”somelibrary.h” normally or conventionally?
a) When former is used, current directory is searched and when latter is used, standard directory is searched
b) When former is used, predefined directory is searched and when latter is used, current directory is searched and then predefined directories are searched
c) When former is used, search is done in implementation defined manner and latter is used to search current directory
d) For both, search for somelibrary is done in implementation-defined manner

  250+ TOP MCQs on Declarations and Answers

Answer: b
Clarification: None.

6. Can function definition be present in header files?
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard

Answer: a
Clarification: None.

7. Comment on the output of the following C code.

  1.     #include 
  2.     #include "test.h"
  3.     #include "test.h"
  4.     int main()
  5.     {
  6.         //some code
  7.     }

a) True
b) Compile time error
c) False
d) Depends on the compiler

Answer: b
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     #define foo(m, n) m ## n
  3.     void myfunc();
  4.     int main()
  5.     {
  6.         myfunc();
  7.     }
  8.     void myfunc()
  9.     {
  10.         printf("%dn", foo(2, 3));
  11.     }

a) 23
b) 2 3
c) Compile time error
d) Undefined behaviour

Answer: a

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top