C Programming Questions and Answers – File Inclusion – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “File Inclusion – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

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
View Answer

Answer: a
Explanation: <> 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
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: b
Explanation: None.

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

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.
advertisement

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

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

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

Answer: a
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.