Exercise: C Preprocessor

Questions for: C Preprocessor

Would the following typedef work?
typedef #include l;
A:
Yes
B:
No
C:
D:
Answer: B
Because typedef goes to work after preprocessing.
Will the program compile successfully?
#include<stdio.h>
#define X (4+Y)
#define Y (X+3)

int main()
{
    printf("%d\n", 4*X+2);
    return 0;
}
A:
Yes
B:
No
C:
D:
Answer: B
Reports an error: Undefined symbol 'X'
Once preprocessing is over and the program is sent for the compilation the macros are removed from the expanded source code.
A:
True
B:
False
C:
D:
Answer: A

True, After preprocessing all the macro in the program are removed.

A preprocessor directive is a message from compiler to a linker.
A:
True
B:
False
C:
D:
Answer: B

FALSE

Example: #define symbol replacement

When the preprocessor encounters #define directive, it replaces any occurrence of symbol in the rest of the code by replacement. This replacement can be an statement or expression or a block or simple text.

The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.
A:
True
B:
False
C:
D:
Answer: B

False, the preprocessor cannot trap the errors, it only replaces the macro with the given expression. But the compiler will detect errors.

Ad Slot (Above Pagination)
Quiz