C Programming Questions and Answers – C-Preprocessor
C Programming Questions and Answers – C-Preprocessor
1.Property which allows to produce different executable for different platforms in C is called?
a) File inclusion
b) Selective inclusion
c) Conditional compilation
d) Recursive macros
View Answer
Explanation:Conditional compilation is the preprocessor facility to produce different executable.
2.#include <stdio.h> is called
a) Preprocessor directive
b) Inclusion directive
c) File inclusion directive
d) None of the mentioned
View Answer
3.C preprocessors can have compiler specific features.
a) true
b) false
c) Depends on the standard
d) Depends on the platform
View Answer
Explanation:#pragma is compiler specific feature.
4.What is the output of this C code?
#include <stdio.h>
#define foo(m, n) m * n = 10
int main()
{
printf(“in main\n”);
}
a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned
View Answer
Explanation:Preprocessor just replaces whatever is given compiler then checks for error at the replaced part of the code. Here it is not replaced anywhere.
Output:
$ cc pgm1.c
$ a.out
in main
5.C preprocessor is conceptually the first step during compilation
a) true
b) false
c) Depends on the compiler
d) Depends on the standard
View Answer
6.Preprocessor feature that supply line numbers and filenames to compiler is called?
a) Selective inclusion
b) macro substitution
c) Concatenation
d) Line control
View Answer
7.#include <somefile.h> are _______ files and #include “somefile.h” ________ files.
a) Library, Library
b) Library, user-created header
c) User-created header, library
d) They can include all types of file
View Answer
Explanation:Both of these statement can be used to select any file.
8.A preprocessor is a program
a) That processes its input data to produce output that is used as input to another program
b) That is nothing but a loader
c) That links various source files
d) All of the mentioned
View Answer
Answer:A preprocessor is a preprocessor is a program that processes its input data to produce output that is used as input to another program.
9.Which of the following are C preprocessors?
a) #ifdef
b) #define
c) #endif
d) All of the mentioned
View Answer
10.#include statement must be written
a) Before main()
b) Before any scanf/printf
c) After main()
d) It can be written anywhere
View Answer
Explanation:Using these directives before main() improves readability.
11.#pragma exit is primarily used for?
a) Checking memory leaks after exitting the program
b) Informing Operating System that program has terminated
c) Running a function at exitting the program
d) No such preprocessor exist
View Answer
Explanation:It is primarily used for running a function upon exitting the program.
12.What is the output of this C code?
#include <stdio.h>
int main()
{
int one = 1, two = 2;
#ifdef next
one = 2;
two = 1;
#endif
printf(“%d, %d”, one, two);
}
a) 1, 1
b) 1, 2
c) 2, 1
d) 2, 2
View Answer
13.The C-preprocessors are specified with _________symbol.
a) #
b) $
c) ” ”
d) None of the mentioned
View Answer
Explanation:The C-preprocessors are specified with # symbol.
14.The #include directive
a) Tells the preprocessor to grab the text of a file and place it directly into the current file
b) Statements are typically placed at the top of a program
c) both a & b
d) None of a & b
View Answer
Explantion:The #include directive tells the preprocessor to grab the text of a file and place it directly into the current file and are statements are typically placed at the top of a program.
15.The preprocessor provides the ability for _______________.
a) The inclusion of header files
b) The inclusion of macro expansions
c) Conditional compilation and line control.
d) All of the mentioned
View Answer
Explanation:The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.
16.If #include is used with file name in angular brackets
a) The file is searched for in the standard compiler include paths
b) The search path is expanded to include the current source directory
c) Both a & b
d) None of the mentioned
View Answer
Explanation:With the #include, if the filename is enclosed within angle brackets, the file is searched for in the standard compiler include paths.