C Programming
C language from basics to advanced placement prep
1,000 Questions 10 Topics Take Test
Advertisement
Showing 31–40 of 1,000 questions
Q.31 Hard Preprocessor
What will happen if we define a macro with the same name as a C standard library function?
A Compilation error
B The macro replaces the function everywhere
C Runtime error
D No effect, function takes precedence
Correct Answer:  B. The macro replaces the function everywhere
EXPLANATION

Macros are textual replacements that happen before compilation. If a macro has the same name as a library function, the macro replaces all occurrences of that name.

Take Test
Q.32 Medium Preprocessor
What is the correct way to define a multi-line macro in C?
A #define MULTI printf("Line1"); printf("Line2");
B #define MULTI printf("Line1") \ printf("Line2")
C Macros cannot span multiple lines
D #define MULTI { printf("Line1"); printf("Line2"); }
Correct Answer:  B. #define MULTI printf("Line1") \ printf("Line2")
EXPLANATION

Backslash (\) at the end of line continues a macro definition to the next line. This is the standard way to create multi-line macros in C.

Take Test
Q.33 Medium Preprocessor
Which of the following about preprocessor is TRUE?
A Preprocessor is part of C compiler
B Preprocessor processes code before compilation
C Preprocessor cannot handle recursive macros
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Preprocessor is a separate tool that processes directives before actual compilation. It prevents recursive macro expansion to avoid infinite loops.

Take Test
Q.34 Medium Preprocessor
What is the output of:
#define MIN(a,b) ((a)
A 5
B 10
C 15
D Compilation error
Correct Answer:  B. 10
EXPLANATION

MIN(10, 5*2) expands to ((10)<(5*2)?(10):(5*2)) = ((10)<(10)?10:10) = 10. Both values are equal due to evaluation order.

Take Test
Q.35 Easy Preprocessor
What does #undef directive do?
A Undefines a previously defined macro
B Checks if macro is undefined
C Includes undefined symbols
D Marks variables as undefined
Correct Answer:  A. Undefines a previously defined macro
EXPLANATION

#undef cancels the definition of a macro, allowing it to be redefined later. After #undef, the macro name becomes undefined.

Take Test
Advertisement
Q.36 Medium Preprocessor
What is the output of:
#define ADD(x,y) (x+y)
int main() { printf("%d", ADD(5,3)*2); return 0; }
A 16
B 13
C Compilation error
D 23
Correct Answer:  A. 16
EXPLANATION

ADD(5,3)*2 expands to (5+3)*2 = 8*2 = 16. Parentheses around the entire macro definition protect against precedence issues.

Take Test
Q.37 Easy Preprocessor
Which header file contains the definition of NULL macro?
A
B
C Both A and B
D
Correct Answer:  C. Both A and B
EXPLANATION

NULL is defined in multiple headers including <stdio.h>, <stdlib.h>, <stddef.h>, and others. Any of these can be included to use NULL.

Take Test
Q.38 Medium Preprocessor
What is the purpose of #pragma pack() directive?
A To define a macro
B To control structure member alignment
C To include header files
D To create string macros
Correct Answer:  B. To control structure member alignment
EXPLANATION

#pragma pack() controls how compiler aligns structure members in memory. #pragma pack(1) minimizes padding, while #pragma pack() without arguments resets to default.

Take Test
Q.39 Medium Preprocessor
What is the issue with this macro: #define MAX(a,b) a>b?a:b
int x = MAX(2, 3); int y = MAX(++i, ++j);
A Syntax error
B Arguments are evaluated multiple times
C No issue
D Type mismatch
Correct Answer:  B. Arguments are evaluated multiple times
EXPLANATION

In MAX(++i, ++j), both i and j are incremented twice due to double evaluation. Parentheses help but don't solve side effects completely.

Take Test
Q.40 Easy Preprocessor
Which predefined macro gives the line number in the source file?
A __FILE__
B __LINE__
C __DATE__
D __STDC__
Correct Answer:  B. __LINE__
EXPLANATION

__LINE__ expands to the current line number. __FILE__ gives filename, __DATE__ gives compilation date, __STDC__ indicates C standard compliance.

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