Behavioral C Preprocessor Interview Preparation Guide
Download PDF

C Preprocessor frequently Asked Questions in various C preprocessor job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting

33 C Preprocessor Questions and Answers:

Table of Contents:

Behavioral  C Preprocessor Job Interview Questions and Answers
Behavioral C Preprocessor Job Interview Questions and Answers

1 :: What is include directive in C?

The include directive is used to include files like as we include header files in the beginning of the program using #include directive like
► #include<stdio.h>
► #include<conio.h></conio.h></stdio.h>

2 :: What is define directive?

It is used to assign names to different constants or statements which are to be used repeatedly in a program. These defined values or statement can be used by main or in the user defined functions as well.

3 :: What are # Preprocessor operator in C?

# is called stringize opertor and turns the argument it precede into a quoted string. Use of # is shown in the C Source code given below and should be properly studied.

4 :: Can a file other than a .h file be included with #include?

The preprocessor will include whatever file you specify in your #include statement. Therefore, if you have the line
#include <macros.inc>
in your program, the file macros.inc will be included in your precompiled program. It is, however, unusual programming practice to put any file that does not have a .h or .hpp extension in an #include statement. You should always put a .h extension on any of your C files you are going to include. This method makes it easier for you and others to identify which files are being used for preprocessing purposes.</macros.inc>

5 :: What are the advantages of using macro?

In modular programming, using functions is advisable when a certain code is repeated several times in a program. However, everytime a function is called the control gets transferred to that function and then back to the calling function. This consumes a lot of execution time. One way to save this time is by using macros. Macros substitute a function call by the definition of that function. This saves execution time to a great extent.

6 :: If you know then define #pragma?

The #pragma Directives are used to turn ON or OFF certain features. They vary from compiler to compiler.

7 :: What is a macro in C Preprocessor?

A macro is a preprocessor directive that provides a mechanism for token replacement in your source code. Macros are created by using the #define statement. Here is an example of a macro:
#define VERSION_STAMP "1.02"

8 :: What is typedf?

The typedef clause can be used in a similar manner.
typedef long int int32; /* 32 bit signed integer */
The typedef is preferred over the #define because is better integrated into the C language, and it can create more kinds of variable types than a mere define.

9 :: 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!

10 :: What is #define?

The #define directive can be used to define types, such as:
#define INT32 long int /* 32 bit signed integer type */

11 :: 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.

12 :: 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>

13 :: What is file in C Preprocessor?

This macro stores the file name of the source file being compiled

14 :: 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.

15 :: What is #line?

#line preprocessor is used to change the values of 2 MACROS , _ _LINE _ _ and _ _ FILE _ _.

16 :: 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>

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

18 :: What are the preprocessor categories?

► Macro substitution division
► File inclusion division
► Compiler control division

19 :: 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.

20 :: 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.

21 :: 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.

22 :: 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.

23 :: 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.

24 :: 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.

25 :: 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.
C Preprocessor Interview Questions and Answers
33 C Preprocessor Interview Questions and Answers