C Programming Questions and Answers – File Inclusion – 2

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

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

1. If the file name is enclosed in double quotation marks, then _________
a) The preprocessor treats it as a user-defined file
b) The preprocessor treats it as a system-defined file
c) The preprocessor treats it as a user-defined file & system-defined file
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

2. If the file name is enclosed in angle brackets, then ___________
a) The preprocessor treats it as a user-defined file
b) The preprocessor treats it as a system-defined file
c) The preprocessor treats it as a user-defined file & system-defined file
d) None of the mentioned
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

3. What will be the output of the following C code snippet?

  1.     #include (stdio.h)
  2.     void main()
  3.     {
  4.         printf("hello");
  5.     }

a) hello
b) Nothing
c) Compile time error
d) Depends on compiler
View Answer

Answer: c
Explanation: File to be included must be specified either in “” or <>.
Output:
$ cc pgm1.c
pgm1.c:1: error: #include expects “FILENAME” or
pgm1.c: In function ‘main’:
pgm1.c:4: warning: incompatible implicit declaration of built-in function ‘printf’

4. The below two lines are equivalent to ________

advertisement
  1.     #define C_IO_HEADER <stdio.h>
  2.     #include C_IO_HEADER

a) #include<stdlib.h>
b) #include”printf”
c) #include”C_IO_HEADER”
d) #include<stdio.h>
View Answer

Answer: d
Explanation: Since C_IO_HEADER is defined to be <stdio.h>, the second line becomes #include<stdio.h>, since C_IO_HEADER is replaced with <stdio.h>
advertisement

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

  1.     #include <stdio.h>
  2.     #include "printf"
  3.     void main()
  4.     {
  5.         printf("hello");
  6.     }

a) hello
b) Error
c) Depends on compiler
d) Varies
View Answer

Answer: b
Explanation: None.

6. Which of the following file extensions are accepted with #include?
a) .h
b) .in
c) .com
d) All of the mentioned
View Answer

Answer: d
Explanation: The preprocessor will include whatever file extension you specify in your #include statement. However, it is not a good practice as another person debugging it will find it difficult in finding files you have included.

7. Which of the following names for files not accepted?
a) header.h.h
b) 123header.h
c) _head_er.h
d) None of the mentioned
View Answer

Answer: d
Explanation: All file names are accepted as for the execution to occur. There are no constraints on giving file names for inclusion.

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.