C Programming Questions and Answers on File Inclusion for Freshers
https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_10.html
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
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
Answer: b
Explanation: The order of file look up is in the sequence of option b, c, a.
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
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
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
Answer: b
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
7. Comment on the output of this C code?
#include#include "test.h"#include "test.h"int main()
{//some code}
a) True
b) Compile time error
c) False
d) Depends on the compiler
b) Compile time error
c) False
d) Depends on the compiler
Answer: b
8. What is the output of this C code?
#include#define foo(m, n) m ## nvoid myfunc();
int main()
{myfunc();
}void myfunc()
{printf("%d\n", foo(2, 3));
}
a) 23
b) 2 3
c) Compile time error
d) Undefined behaviour
b) 2 3
c) Compile time error
d) Undefined behaviour
Answer: a
9. If the file name is enclosed in double quotation marks
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
Answer: a
10. If the file name is enclosed in angle brackets
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
Answer: b
11. What is the output of this C code?
#include (stdio.h)void main()
{printf("hello");
}
a) hello
b) Nothing
c) Compile time error
d) Depends on compiler
b) Nothing
c) Compile time error
d) Depends on compiler
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’
12. The below two lines are equivalent to
#define C_IO_HEADER
#include C_IO_HEADER
#define C_IO_HEADER
#include C_IO_HEADER
a) #include
b) #include”printf”
c) #include”C_IO_HEADER”
d) #include
Answer: d
Explanation: Since C_IO_HEADER is defined to be
13. What is the output of this C code?
#include#include "printf"void main()
{printf("hello");
}
a) hello
b) Error
c) Depends on compiler
d) Varies
b) Error
c) Depends on compiler
d) Varies
Answer: a
14. Which of the following file extensions are accepted with #include?
a) .h
b) .in
c) .com
d) All of the mentioned
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 difficulty in finding files you have included.
15. 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
Answer: d
Explanation: All file names are accepted as for the execution to occur. There are no constraints on giving file names for inclusion.
