Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 81–90 of 1,000
Topics in C Programming
Q.81 Easy Preprocessor
What is the primary role of the C preprocessor in the compilation process?
A It processes source code before actual compilation and performs text substitutions
B It executes the program after compilation
C It handles memory allocation during runtime
D It manages hardware resources
Correct Answer:  A. It processes source code before actual compilation and performs text substitutions
EXPLANATION

The preprocessor is a separate program that processes source code before the compiler. It handles directives like #include, #define, and #ifdef.

Take Test
Q.82 Hard Preprocessor
What preprocessor features should be avoided for safer code?
A Object-like macros only
B Function-like macros due to side effects and lack of type safety
C #include directives
D Conditional compilation
Correct Answer:  B. Function-like macros due to side effects and lack of type safety
EXPLANATION

Function-like macros can cause issues due to multiple evaluation of arguments and operator precedence problems. Modern C prefers inline functions and const for safety.

Take Test
Q.83 Hard Preprocessor
What is the difference between #if and #ifdef?
A #if checks macro values, #ifdef checks if defined
B Both are identical
C #ifdef is deprecated
D #if is only for integers
Correct Answer:  A. #if checks macro values, #ifdef checks if defined
EXPLANATION

#ifdef checks if a macro is defined (exists). #if evaluates a constant integer expression (can check macro values, compare numbers, etc.).

Take Test
Q.84 Hard Preprocessor
What will be the output?
#define MIN(a,b) ((a)
A z=5, x=6, y=11
B z=5, x=7, y=11
C Undefined behavior
D z=5, x=6, y=10
Correct Answer:  A. z=5, x=6, y=11
EXPLANATION

The macro expands to ((x++)<(y++)?(x++):(y++)). In the condition, x++ returns 5 and increments x to 6. Since 5<10 is true, x++ is evaluated again (x becomes 7, but z gets 6). Actually, this shows side effects problem - x becomes 7, y stays 10.

Take Test
Q.85 Hard Preprocessor
What is the problem with this macro?
#define DOUBLE(x) x*x
int result = DOUBLE(2+3);
A No problem, result is 25
B Result is 11 due to operator precedence
C Compilation error
D Result is undefined
Correct Answer:  B. Result is 11 due to operator precedence
EXPLANATION

The macro expands to 2+3*2+3 = 2+6+3 = 11, not 25. This is because x is not parenthesized. Should use #define DOUBLE(x) ((x)*(x))

Take Test
Q.86 Hard Preprocessor
Which statement about #define is TRUE?
A Macros are type-safe like functions
B Macros do not allocate memory at runtime
C Macros cannot take arguments
D Macros are evaluated at runtime
Correct Answer:  B. Macros do not allocate memory at runtime
EXPLANATION

Macros are purely textual substitutions performed by the preprocessor at compile time, not at runtime. They don't allocate memory themselves.

Take Test
Q.87 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.

Take Test
Q.88 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.

Take Test
Q.89 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.

Take Test
Q.90 Easy Preprocessor
What is the purpose of the #undef directive?
A To undefine a previously defined macro
B To prevent macro expansion
C To create undefined behavior
D To test if a macro is undefined
Correct Answer:  A. To undefine a previously defined macro
EXPLANATION

#undef is used to remove the definition of a macro so it cannot be used in subsequent code.

Take Test
IGET
iget AI
Online · Ask anything about exams
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