C preprocessor Interview Questions & Answers

C preprocessor Interview Questions

What to shift your career to C Pre-processor Interview Questions? Then we have provided you with the complete details about the C Pre-processor Interview Question and Answers on our site page. Carking an interview at very first attempt need very hard working and should have a good knowledge on all concepts as well. The C pre-processor or cpp is the macro pre-processor for the C and C++ computer programming languages. The pre-processor delivers the aptitude for the presence of header files, macro expansions, conditional compilation, and line control. If you are good at the C Pre-processor concepts then there are various companies that offer job roles like Web Developer, Magento Developer, Fabric Developer, OnBase Developer and many other roles too. For any other further details on C Pre-processor jobs visit our site www.wisdomjobs.com.

C Preprocessor Interview Questions And Answers

C preprocessor Interview Questions
    1. Question 1. What Is Include Directive In C?

      Answer :

      The include directive is used to include files like as we include header files in the beginning of the program using include directive like


    2. Question 2. What Is Define Directive?

      Answer :

      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. Question 3. What Are # Preprocessor Operator In C?

      Answer :

      # 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. Question 4. Can A File Other Than A .h File Be Included With #include?

      Answer :

      The preprocessor will include whatever file you specify in your #include statement. Therefore, if you have the line


      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.

    5. Question 5. What Are The Advantages Of Using Macro?

      Answer :

      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. Question 6. If You Know Then Define #pragma?

      Answer :

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

    7. Question 7. What Is A Macro In C Preprocessor?

      Answer :

      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. Question 8. What Is Typedf?

      Answer :

      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. Question 9. What Is The Mean Of Function?

      Answer :

      Functions allow for modular programming. You must remember that all parameters passed into function in C are passed by value!

    10. Question 10. What Is #define?

      Answer :

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

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

    11. Question 11. What Is ## Preprocessor Operator In C?

      Answer :

      ## is called the pasting opertor which is used to concates two tokens. Use of ## is shown in the source code.

    12. Question 12. What Is The General Form Of #line Preprocessor?

      Answer :

      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 -

      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;

    13. Question 13. What Is File In C Preprocessor?

      Answer :

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

    14. Question 14. What Is Line In C Preprocessor?

      Answer :

      This a dynamic macro which stores the line number of the line presently being compiled. Value is constantly updated as compiler moves forward.

    15. Question 15. What Is #line?

      Answer :

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

    16. Question 16. What Is #error And Use Of It?

      Answer :

      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 -

      int main ()
      #error I am Error and while i am here i will not let this program compile :-) .
      return 0;

    17. Question 17. Where Define Directive Used?

      Answer :

      • Defining a constant
      • Defining a statement
      • Defining a mathematical expression

      For example

      • #define PI 3.141593
      • #define TRUE 1
      • #define floatingpointno float

    18. Question 18. What Are The Preprocessor Categories?

      Answer :

      • Macro substitution division
      • File inclusion division
      • Compiler control division

    19. Question 19. What Are Types Of Preprocessor In C?

      Answer :

      • #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. Question 20. What Are The Advantages Of C Preprocessor?

      Answer :

      • Programs easier to develop,
      • Easier to read,
      • Easier to modify
      • C code more transportable between different machine architectures.

    21. Question 21. What Is C Preprocessor Mean?

      Answer :

      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. Question 22. What Is Cpp?

      Answer :

      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. Question 23. Do You Have Any Idea About The Use Of "auto" Keyword?

      Answer :

      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.

    24. Question 24. Can You Please Explain The Scope Of Static Variables?

      Answer :

      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.

    25. Question 25. What Do You Know About The Use Of Bit Field?

      Answer :

      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.

    26. Question 26. Tell Us Bitwise Shift Operators?

      Answer :

      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


      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'.

Popular Interview Questions

All Interview Questions

C Preprocessor Practice Test

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

C Tutorial