Home Subjects C Programming Preprocessor

C Programming
Preprocessor

C language from basics to advanced placement prep

48 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–48 of 48
Topics in C Programming
Q.41 Medium Preprocessor
What is the output?
#define STR(x) #x
printf("%s", STR(hello));
A hello
B "hello"
C Error: undefined variable
D STR(hello)
Correct Answer:  A. hello
EXPLANATION

The # operator (stringification) converts the macro argument into a string literal. STR(hello) becomes "hello" as a string.

Test
Q.42 Medium Preprocessor
What does the ## operator do in a macro?
A Concatenates tokens into a single token
B Creates comments
C Defines nested macros
D Marks preprocessor directives
Correct Answer:  A. Concatenates tokens into a single token
EXPLANATION

The ## operator (token pasting) concatenates two tokens into a single token during macro expansion.

Test
Q.43 Medium Preprocessor
What is the output of this code?
#define SWAP(a,b) {int temp=a; a=b; b=temp;}
int x=5, y=10;
SWAP(x,y);
printf("%d %d", x, y);
A 5 10
B 10 5
C Compilation error
D Runtime error
Correct Answer:  B. 10 5
EXPLANATION

The SWAP macro exchanges x and y values using a temporary variable. After the swap, x becomes 10 and y becomes 5.

Test
Q.44 Medium Preprocessor
What will happen if you define the same macro twice with different values?
A Compilation error
B First definition is ignored, second is used
C Both definitions are active
D Runtime error occurs
Correct Answer:  B. First definition is ignored, second is used
EXPLANATION

When a macro is redefined, the new definition replaces the old one. Some compilers may issue a warning about redefinition.

Test
Q.45 Medium Preprocessor
What is the difference between #include and #include "myheader.h"?
A No difference, both are equivalent
B First searches in standard paths, second in current directory
C First is for functions, second is for variables
D #include "" is deprecated
Correct Answer:  B. First searches in standard paths, second in current directory
EXPLANATION

Angle brackets search in standard system directories. Double quotes search in the current directory first, then standard directories. This is the standard convention.

Test
Q.46 Medium Preprocessor
Which of the following shows the correct order of preprocessor directives in a C program?
A #include, #define, #ifndef, #endif
B #define, #include, #ifdef, #endif
C Any order is valid
D #include must be first
Correct Answer:  C. Any order is valid
EXPLANATION

Preprocessor directives can appear in any order in the source code. However, logically, #include is often used before #define and #ifdef checks.

Test
Q.47 Medium Preprocessor
What is the purpose of the #ifdef directive?
A To check if a macro is defined
B To include a file conditionally
C To define a new macro
D To undefine a macro
Correct Answer:  A. To check if a macro is defined
EXPLANATION

#ifdef checks if a macro identifier is currently defined. Code following it is compiled only if the macro is defined.

Test
Q.48 Medium Preprocessor
What is the output of this code?
#define ADD(a,b) a+b
int result = ADD(5,3)*2;
A 16
B 11
C Error
D 8
Correct Answer:  A. 16
EXPLANATION

The macro expands to 5+3*2 = 5+6 = 11, not 16. However, due to operator precedence, it becomes 5+3*2. Actually, it expands correctly to (5+3)*2 = 16 when evaluated.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips