C Preprocessor Interview Questions And Answers
Download C Preprocessor Interview Questions and Answers PDF
Enhance your C Preprocessor interview preparation with our set of 33 carefully chosen questions. Each question is designed to test and expand your C Preprocessor expertise. Suitable for all experience levels, these questions will help you prepare thoroughly. Don't miss out on our free PDF download, containing all 33 questions to help you succeed in your C Preprocessor interview. It's an invaluable tool for reinforcing your knowledge and building confidence.
33 C Preprocessor Questions and Answers:
C Preprocessor Job Interview Questions Table of Contents:
1 :: Tell us bitwise shift operators?
The bitwise operators are used for shifting the bits of the first operand left or right. The number of shifts is specified by the second operator.
Expression << or >> number of shifts
Ex:
number<<3;/* number is an operand - shifts 3 bits towards left*/
number>>2; /* number is an operand – shifts 2 bits towards right*/
The variable number must be an integer value.
For leftward shifts, the right bits those are vacated are set to 0. For rightward shifts, the left bits those are vacated are filled with 0’s based on the type of the first operand after conversion.
If the value of ‘number’ is 5, the first statement in the above example results 40 and stored in the variable ‘number’.
If the value of ‘number’ is 5, the second statement in the above example results 0 (zero) and stored in the variable ‘number’.
Read MoreExpression << or >> number of shifts
Ex:
number<<3;/* number is an operand - shifts 3 bits towards left*/
number>>2; /* number is an operand – shifts 2 bits towards right*/
The variable number must be an integer value.
For leftward shifts, the right bits those are vacated are set to 0. For rightward shifts, the left bits those are vacated are filled with 0’s based on the type of the first operand after conversion.
If the value of ‘number’ is 5, the first statement in the above example results 40 and stored in the variable ‘number’.
If the value of ‘number’ is 5, the second statement in the above example results 0 (zero) and stored in the variable ‘number’.
2 :: What do you know about the use of bit field?
Packing of data in a structured format is allowed by using bit fields. When the memory is a premium, bit fields are extremely useful. For example:
- Picking multiple objects into a machine word : 1 bit flags can be compacted
- Reading external file formats : non-standard file formats could be read in, like 9 bit integers
This type of operations is supported in C language. This is achieved by putting :’bit length’ after the variable. Example:
struct packed_struct {
unsigned int var1:1;
unsigned int var2:1;
unsigned int var3:1;
unsigned int var4:1;
unsigned int var5:4;
unsigned int funny_int:9;
} pack;
packed-struct has 6 members: four of 1 bit flags each, and 1 4 bit type and 1 9 bit funny_int.
C packs the bit fields in the structure automatically, as compactly as possible, which provides the maximum length of the field is less than or equal to the integer word length the computer system.
The following points need to be noted while working with bit fields:
The conversion of bit fields is always integer type for computation
Normal types and bit fields could be mixed / combined
Unsigned definitions are important.
Read More- Picking multiple objects into a machine word : 1 bit flags can be compacted
- Reading external file formats : non-standard file formats could be read in, like 9 bit integers
This type of operations is supported in C language. This is achieved by putting :’bit length’ after the variable. Example:
struct packed_struct {
unsigned int var1:1;
unsigned int var2:1;
unsigned int var3:1;
unsigned int var4:1;
unsigned int var5:4;
unsigned int funny_int:9;
} pack;
packed-struct has 6 members: four of 1 bit flags each, and 1 4 bit type and 1 9 bit funny_int.
C packs the bit fields in the structure automatically, as compactly as possible, which provides the maximum length of the field is less than or equal to the integer word length the computer system.
The following points need to be noted while working with bit fields:
The conversion of bit fields is always integer type for computation
Normal types and bit fields could be mixed / combined
Unsigned definitions are important.
3 :: Can you please explain the scope of static variables?
Static variables in C have the scopes;
1. Static global variables declared at the top level of the C source file have the scope that they can not be visible external to the source file. The scope is limited to that file.
2. Static local variables declared within a function or a block, also known as local static variables, have the scope that, they are visible only within the block or function like local variables. The values assigned by the functions into static local variables during the first call of the function will persist / present / available until the function is invoked again.
The static variables are available to the program, not only for the function / block. It has the scope within the current compile. When static variable is declared in a function, the value of the variable is preserved , so that successive calls to that function can use the latest updated value. The static variables are initialized at compile time and kept in the executable file itself. The life time extends across the complete run of the program.
Static local variables have local scope. The difference is, storage duration. The values put into the local static variables, will still be present, when the function is invoked next time.
Read More1. Static global variables declared at the top level of the C source file have the scope that they can not be visible external to the source file. The scope is limited to that file.
2. Static local variables declared within a function or a block, also known as local static variables, have the scope that, they are visible only within the block or function like local variables. The values assigned by the functions into static local variables during the first call of the function will persist / present / available until the function is invoked again.
The static variables are available to the program, not only for the function / block. It has the scope within the current compile. When static variable is declared in a function, the value of the variable is preserved , so that successive calls to that function can use the latest updated value. The static variables are initialized at compile time and kept in the executable file itself. The life time extends across the complete run of the program.
Static local variables have local scope. The difference is, storage duration. The values put into the local static variables, will still be present, when the function is invoked next time.
4 :: Do you have any idea about the use of "auto" keyword?
When a certain variable is declared with the keyword ‘auto’ and initialized to a certain value, then within the scope of the variable, it is reinitialized upon being called repeatedly.
Read More5 :: 1. Which of the following are C preprocessors?
a) #ifdef
b) #define
c) #endif
d) All of the mentioned
d
(All of the mentioned)
Read More(All of the mentioned)
6 :: #include statement must be written
a) Before main()
b) Before any scanf/printf
c) After main()
d) It can be written anywhere
b
(Before any scanf/printf)
Explanation:Using these directives before main() improves readability.
Read More(Before any scanf/printf)
Explanation:Using these directives before main() improves readability.
7 :: #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
c
(Running a function at exitting the program)
Explanation:It is primarily used for running a function upon exitting the program.
Read More(Running a function at exitting the program)
Explanation:It is primarily used for running a function upon exitting the program.
8 :: The C-preprocessors are specified with _________symbol.
a) #
b) $
c) " "
d) None of the mentioned
a
(#)
Explanation:The C-preprocessors are specified with # symbol.
Read More(#)
Explanation:The C-preprocessors are specified with # symbol.
9 :: 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
c
(both a & b)
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.
Read More(both a & b)
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.
10 :: 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
d
(All of the mentioned)
Explanation:The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.
Read More(All of the mentioned)
Explanation:The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.
11 :: 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
a
(The file is searched for in the standard compiler include paths)
Explanation:With the #include, if the filename is enclosed within angle brackets, the file is searched for in the standard compiler include paths.
Read More(The file is searched for in the standard compiler include paths)
Explanation:With the #include, if the filename is enclosed within angle brackets, the file is searched for in the standard compiler include paths.
12 :: What is cpp?
The preprocessor is called cpp, however it is called automatically by the compiler so you will not need to call it while programming in C.
Read More13 :: What is C Preprocessor mean?
The C preprocessor is a tool which filters your source code before it is compiled. The preprocessor allows constants to be named using the #define notation.It is particularly useful for selecting machine dependent pieces of code for different computer types, allowing a single program to be compiled and run on several different computers.
Read More14 :: What are the advantages of C Preprocessor?
► Programs easier to develop,
► Easier to read,
► Easier to modify
► C code more transportable between different machine architectures.
Read More► Easier to read,
► Easier to modify
► C code more transportable between different machine architectures.
15 :: What are types of Preprocessor in C?
► #define and #undef - Used for defining and undefining MACROS.
► #error - Used for Debugging
► #include - Used for combining source code files
► #if, #else, #elseif, and #endif - Used for conditional compilation similar to if - else statment.
► #ifdef and #ifndef - Conditional Compilation on basis of #define and #undef
► #line - Controls the program line and file macros.
► #pragma - Used for giving compiler instruction. Highly specific to the compiler being used.
► # and ## - Operators used for stringize and concating operation respectively.
Read More► #error - Used for Debugging
► #include - Used for combining source code files
► #if, #else, #elseif, and #endif - Used for conditional compilation similar to if - else statment.
► #ifdef and #ifndef - Conditional Compilation on basis of #define and #undef
► #line - Controls the program line and file macros.
► #pragma - Used for giving compiler instruction. Highly specific to the compiler being used.
► # and ## - Operators used for stringize and concating operation respectively.
16 :: What are the preprocessor categories?
► Macro substitution division
► File inclusion division
► Compiler control division
Read More► File inclusion division
► Compiler control division
17 :: Where define directive used?
► Defining a constant
► Defining a statement
► Defining a mathematical expression
For example
► #define PI 3.141593
► #define TRUE 1
► #define floatingpointno float
Read More► Defining a statement
► Defining a mathematical expression
For example
► #define PI 3.141593
► #define TRUE 1
► #define floatingpointno float
18 :: What is #error and use of it?
The use of this preprocessor is in debugging. Whenever this preprocessor is encountered during compilation the compiler would stop compilation and display the error message associated with the preprocessor in complation Output/Result Window. Depending upon compiler any other debugging information will also accompany your error message.
General form of #error is -
#error message
Also note that message doesnot need to be in double quotes.
Following source code display the use of #error preprocessor directive in C -
#include <stdio.h>
int main ()
{
#error I am Error and while i am here i will not let this program compile :-) .
return 0;
}</stdio.h>
Read MoreGeneral form of #error is -
#error message
Also note that message doesnot need to be in double quotes.
Following source code display the use of #error preprocessor directive in C -
#include <stdio.h>
int main ()
{
#error I am Error and while i am here i will not let this program compile :-) .
return 0;
}</stdio.h>
19 :: What is #line?
#line preprocessor is used to change the values of 2 MACROS , _ _LINE _ _ and _ _ FILE _ _.
Read More20 :: What is line in C Preprocessor?
This a dynamic macro which stores the line number of the line presently being compiled. Value is constantly updated as compiler moves forward.
Read More21 :: What is file in C Preprocessor?
This macro stores the file name of the source file being compiled
Read More22 :: What is the general form of #line preprocessor?
General form of #line preprocessor is #line number "filename"
Here the file name is optional. Filename string replaces the string value of _ _FILE_ _ while the number changes the value of _ _LINE_ _.
The major use of #line is in debugging and rare programming situation.
Following C Source code shows the #line preprocessor in action -
#include <stdio.h>
int main ()
{
printf ("n%d", __LINE__); //Prints 6
#line 100;
printf ("n%d",__LINE__); // Prints 101
printf ("n%d", __FILE__);// Prints original source file name
#line 103 "Super C"
printf ("n%d", __FILE__); //Prints Super C
return 0;
}</stdio.h>
Read MoreHere the file name is optional. Filename string replaces the string value of _ _FILE_ _ while the number changes the value of _ _LINE_ _.
The major use of #line is in debugging and rare programming situation.
Following C Source code shows the #line preprocessor in action -
#include <stdio.h>
int main ()
{
printf ("n%d", __LINE__); //Prints 6
#line 100;
printf ("n%d",__LINE__); // Prints 101
printf ("n%d", __FILE__);// Prints original source file name
#line 103 "Super C"
printf ("n%d", __FILE__); //Prints Super C
return 0;
}</stdio.h>
23 :: What is ## Preprocessor operator in C?
## is called the pasting opertor which is used to concates two tokens. Use of ## is shown in the source code.
Read More24 :: What is #define?
The #define directive can be used to define types, such as:
#define INT32 long int /* 32 bit signed integer type */
Read More#define INT32 long int /* 32 bit signed integer type */
25 :: What is the mean of function?
Functions allow for modular programming. You must remember that all parameters passed into function in C are passed by value!
Read More