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.

advertisement

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

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.

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

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.