Javatpoint Logo
Javatpoint Logo

C Preprocessor Test 4


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

  1. Hello\n Welcome to javatpoint\n
  2. Hello Welcome to javatpoint
  3. Hello Welcome to javatpoint
  4. Compile error

The correct option is (b).

Explanation:

  • The name of a file can also be used as name of expansion.
  • The preprocessor directive #include can be used anywhere in the program.

During preprocessing, the macro MYFILE gets replaced with <stdio.h>, then program is compiled and executed as shown below:

Therefore the output of program is:

Hello

Welcome to javatpoint

17) Will it be result in to an error if a header file is included twice in a program?

  1. Yes
  2. No
  3. It is compiler dependent

The correct option is (c).

Explanation:

In GCC compilers and Turbo C the compiler would take care of these problems and it generates no error. In other compilers the error may occur.

Unless the header file has taken care for ensure that if already included then it doesn't get included again.

Therefore an error in a program due to use of header file twice in a program is compiler dependent.

18) The preprocessor can trap simple error like nested comments, mismatch of braces or missing declarations.

  1. True
  2. False

The correct option is (b).

Explanation:

The statement is false because the preprocessor cannot trap the errors; it only replaces the macro with the given expression.

The compiler is used for detecting an error in a program.

19) In every C program there is at least one preprocessor directive.

  1. True
  2. False

The correct option is (b).

Explanation:

The statement is false because the preprocessor directive is not compulsory in any C program. We can also develop a program in C language without using any preprocessor directive.

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

  1. 5
  2. 9
  3. 8
  4. 6

The correct option is (d).

Explanation:

The macro MAX(x, y) (x > y ? x : y) returns the biggest value of the given two numbers.

Step 1: int a; The variable 'a' is declared as an integer type.

Step 2: a = MAX(3+1, 2+4); becomes,

=> a = (3+1 > 2+4 ? 3+1 : 2+4)

=> a = (4 > 6 ? 4 : 6)

=> a = 6

Step 3: printf("%d\n", a); It prints the value of variable 'a'.

Hence the output of the program is 6.

Next Topic#





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