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

C Preprocessor Questions and Answers

41.

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.

42.

What is the output generated by the following code?

#define square(a) (a*a)
printf("%d", square(4+5));

Answer: C

Correct answer: 29

The macro has no parentheses round its parameter, so the argument is pasted in as raw text:

printf("%d", (4+5*4+5));

Multiplication binds tighter than addition, giving \(4 + 20 + 5 = 29\) rather than the intended \(9^2 = 81\). Parenthesising the parameter - #define square(a) ((a)*(a)) - is what fixes it.

Please log in or register to report this question.

43.

Undefined function calls in a C program are detected

Answer: C

Correct answer: by the linker

The compiler is satisfied by a declaration: it only needs to know the function’s signature to generate a call. Whether a definition actually exists is settled when the object files and libraries are combined, so a missing function surfaces as a linker error - the familiar “undefined reference”.

Please log in or register to report this question.

44.

Identify the macro(s) defined in stdarg.h.

Answer: D

Correct answer: all the above

<stdarg.h> defines all three: va_start to begin walking the variable argument list, va_arg to fetch the next argument (given its type), and va_end to finish. They are what a function such as printf uses to reach arguments the compiler cannot type-check.

Please log in or register to report this question.

Answer: B

Correct answer: a predefined data type in stdarg.h

va_list is a type - a typedef declared in <stdarg.h> - used to declare the object that holds the state of the walk through the variable arguments. va_start, va_arg and va_end are the macros that operate on it.

Please log in or register to report this question.

46.

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.

47.

Identify the stringizing operator.

Answer: C

Correct answer: #

A single # before a macro parameter is the stringizing operator: it turns the argument’s text into a string literal, so #define str(x) #x makes str(hello) become "hello". The double ## is a different operator - it pastes two tokens into one.

Please log in or register to report this question.

48.

The EOF character can be included in a file as part of its data

Answer: B

Correct answer: FALSE

EOF is not a character at all. It is a macro in <stdio.h> expanding to a negative integer, usually -1, which getchar and its relatives return to signal that no more input is available. Since it is outside the range of an unsigned char, it cannot be one of the bytes stored in a file. (This is why getchar returns int rather than char.)

Please log in or register to report this question.

49.

The NULL character indicates an end of a string and a file.

Answer: B

Correct answer: FALSE

The null character marks the end of a string in memory, and nothing more. A file’s end is not marked by any byte within it: it is known from the file’s recorded length, and reported to the program as EOF. A file may perfectly well contain null bytes as data - every binary file does.

Please log in or register to report this question.

50.

What will be the output of the following C code?

#include <stdio.h>
#define max 100
main()
{
    #ifdef max
    printf("hello");
}

 

Answer: D

The code shown above results in an error. This is because the preprocessor #endif is missing in the above code. If the identifier is defined, then the statements following #ifdef are executed till #endif is encountered.

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