Javatpoint Logo
Javatpoint Logo

C Preprocessor Test 3


11) Which operator is used for continue the definition of macro in the next line?

  1. $
  2. #
  3. ##
  4. \

The correct option is (d).

Explanation:

There is no such operator called $. The second and third operator are used for stringize and token pasting operators respectively.

Therefore the operator '\' is used for continue the definition of macro in the next line.

12) Select the invalid predefined macro as per ANSI C.

  1. __DATE__
  2. __TIME__
  3. __C++__
  4. __FILE__

The correct option is (c).

Explanation:

There is no such macro defined with the name __C++__, but the __cplusplus__ is predefined macro as per ANSI C specification.

Therefore the __C++__ is invalid predefined macro as per ANSI C.

13) Find out the error in the below program?

  1. The number is even
  2. Error: unexpected end of file because there is no matching #endif
  3. Garbage values
  4. None of the above

The correct option is (b).

Explanation:

The conditional macro statement #if must have an #endif statement. In the program there is no #endif statement used.

Therefore the program returns an Error: unexpected end of file because there is no matching #endif.

14) Which of the following are correct preprocessor directives in C language?

  1. #undef
  2. #elif
  3. #if
  4. #ifdef
  1. 1, 2, 4
  2. 1, 3, 4
  3. 1, 4
  4. 1, 2, 3, 4

The correct option is (d).

Explanation:

The macro statement #undef undefined the previously declared macro symbol.

The macro statement #if #ifdef #elif are called conditional macros.

Hence all the given statements are correct macro preprocessor directives in C language.

15) What will be the output of the below program on GCC compiler?

  1. Mean of 5 numbers=3
  2. Mean of 5 numbers=5
  3. Mean of 5 numbers=1
  4. Compile error

The correct option is (a).

Explanation:

In a program the macro MEAN is defined with an expansion.

During preprocessing, the occurrence of MEAN is replaced with their expansion, then send to compiler and program is executed as below:

Therefore the output of the above program is "Mean of 5 numbers=3".





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA