C Programming Questions and Answers – File Inclusion – 1

«
»
This section on C programming quiz focuses on “File Inclusion”. One shall practice these quizzes to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C quiz comes with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of 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
View Answer

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

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.

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.
advertisement
advertisement

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: d
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.
advertisement

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.

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

advertisement
  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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter