Machine-translated by Google. Questions are authored in English.
Top

C Preprocessor Questions and Answers

81.

What is the output of this program?

#include <stdio.h>
#define clrscr() 17
int main()
{
  clrscr();
  printf("%d",clrscr());
  return 0;
}

 

Answer: C

Correct answer: 17

clrscr() is a function-like macro expanding to the constant 17. The first call becomes the statement 17;, which computes a value and discards it - legal, if pointless. The printf then expands to printf("%d", 17) and prints 17.

Please log in or register to report this question.

82.

If the file to be included doesn't exist, the preprocessor flashes an error message.

Answer: A

Correct answer: True

If the named file cannot be found on any of the search paths, the preprocessor reports a fatal error and translation stops - the familiar “No such file or directory”. Nothing reaches the compiler, so the missing header is discovered before any C is parsed.

Please log in or register to report this question.

83.

A preprocessor directive is a message from programmer to the preprocessor.

Answer: A

Correct answer: True

A directive such as #include or #define is an instruction to the preprocessor - the phase that rewrites the source text before the compiler sees it. It is not part of the C language proper, which is why it has its own syntax and ends at the end of a line rather than at a semicolon.

Please log in or register to report this question.

84.

A line in a program consisting of nothing but a # represents

Answer: B

Correct answer: a null directive

A # on a line by itself is the null directive: the preprocessor recognises it, does nothing, and removes it. It is legal and occasionally used as a spacer inside a run of conditionals to keep the nesting readable.

Please log in or register to report this question.

85.

Identify the trigraph sequence for ^.

Answer: C

Correct answer: ??'

The trigraph for the caret is ??'. The full set is ??= for #, ??/ for backslash, ??' for ^, ??( and ??) for the square brackets, ??! for |, ??< and ??> for the braces, and ??- for ~.

Please log in or register to report this question.

86.

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

Answer: B

Correct answer: False

The preprocessor does not parse C at all. It handles directives, expands macros and strips comments; it has no notion of declarations or of matching braces, so those errors surface later, in the compiler. It does report its own faults, such as a missing include file or an unclosed #if.

Please log in or register to report this question.

87.

The C-preprocessors are specified with _________symbol.

Answer: A

Correct answer: #

Every preprocessor directive begins with # as the first non-blank character of the line. The symbol is what marks the line as an instruction to the preprocessor rather than a piece of C.

Please log in or register to report this question.

88.

What is the output for the following code snippet?

#include <stdio.h>
#define A -B
#define B -C
#define C 5

int main()
{
  printf("The value of A is %d\n", A); 
  return 0;
} 

 

Answer: B

Correct answer: The value of A is 5

Macros are rescanned after expansion, so the substitution cascades:

A → -B → -(-C) → -(-5)

Two negations cancel, so the value printed is 5.

Please log in or register to report this question.

89.

Macro calls and function calls work exactly similarly.

Answer: B

False, A macro just replaces each occurrence with the code assigned to it. e.g. SQUARE(3) with ((3)*(3)) in the program.

A function is compiled once and can be called from anywhere that has visibility to the funciton.

Please log in or register to report this question.

90.

What will be the output of the program?

#include <stdio.h>
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)

int main()
{
    int x;
    x = MAX(3+2, 2+7, 3+7);
    printf("%d\n", x);
    return 0;
}

 

Answer: C

Correct answer: 10

The macro expands to a nested conditional. With \(a = 3+2 = 5\), \(b = 2+7 = 9\) and \(c = 3+7 = 10\):

(5>9 ? … : 9>10 ? 9 : 10)

The first test fails, so the else branch is taken; \(9 > 10\) also fails, leaving 10. Addition binds tighter than the comparisons, so the unparenthesised arguments happen to be safe here.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: C Preprocessor Questions and Answers || C Preprocessor MCQ Questions and Answers || C Preprocessor GK Questions and Answers || C Preprocessor GK MCQ Questions || C Preprocessor Multiple Choice Questions and Answers || C Preprocessor GK || GK on C Preprocessor || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming