Javatpoint Logo
Javatpoint Logo

C Preprocessor Test 2


6) What will be the output of the below program?

  1. square of j=9
  2. j=3
  3. Compile error
  4. No output

The correct option is (a).

Explanation:

In program #ifdef, #else and #endif are preprocessor commands.

If the macro DEF is defined by a #define statement, then the code immediately after #ifdef is compiled otherwise code between #else and #endif commands gets executed. Since, DEF has been defined, #ifdef DEF evaluates to true hence, square of 'j' is calculated and gets printed i.e 9.

While defining the macro DEF, it is not compulsory to provide a expansion to the macro statement because in a program we are not using the value of macro expansion.

Therefore the output of the program is square of j=9.

7) What will be the output of the below program?

  1. Gross salary=1000
  2. Gross salary=1400
  3. Compile error
  4. No output

The correct option is (b).

Explanation:

When the preprocessor sends the program for compilation IT, HRA and DA have been replaced by 0.1, 0.2 and 0.3 respectively. With the bas_sal set to 1000, the net salary is calculated as:

The statement printf("Gross salary=%f\n", net_sal); prints the result. Therefore the output of Output:

Gross salary=1400

8) It is necessary that header files must have the .h extension?

  1. Yes
  2. No

The correct option is (b).

Explanation:

No, the header files may have any extension. It is not necessary that header file must have .h extension.

9) Which header file is used for supporting the functions- malloc() and calloc().

  1. stdio.h
  2. math.h
  3. stdlib.h
  4. memory.h

The correct option is (c).

Explanation:

void *calloc(size_h nitems, size_h size): Function calloc() requires the double argument.

void *malloc(size_h size): Function malloc() requires the single argument.

For supporting the function- malloc() and calloc() stdlib.h header file is required.

10) A macro statement can execute faster than function.

  1. True
  2. False

The correct option is (a).

Explanation:

Macro statement can be executed faster with no overhead of context switch because the code of macro gets expanded at the line of call.

Therefore the above statement is true.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA