C Preprocessor

  Home  C Language  C Preprocessor


“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

21⟩ 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

 128 views

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

 140 views

23⟩ 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

► #include

 136 views

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

 134 views

25⟩ 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

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.

 139 views

26⟩ 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.

 140 views

27⟩ 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.

 132 views

28⟩ What is #define?

The #define directive can be used to define types, such as:

#define INT32 long int /* 32 bit signed integer type */

 135 views

29⟩ 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.

 130 views

31⟩ 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!

 152 views

32⟩ 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"

 145 views

33⟩ 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

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;

}

 143 views