Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

Practice C Programming MCQ questions with detailed answers and step-by-step explanations. 978+ free questions available with instant solutions — perfect for competitive exam preparation.
978 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 978
Topics in C Programming
Q.1 Medium Preprocessor
Consider the following preprocessor directives:
#define MAX 100
#define MIN 50
#undef MAX
#define MAX 200

int main() {
printf("%d", MAX);
return 0;
}

What will be the output of this program?
A 200
B 100
C Compilation error
D 50
Correct Answer:  A. 200
EXPLANATION

The #undef directive undefines the previously defined macro MAX (which was 100). Then MAX is redefined as 200. So printf will output 200. The #undef allows redefining macros without compilation errors.

Test
Q.2 Hard Preprocessor
What will happen if a macro is defined multiple times with different definitions in the same compilation unit?
#define SIZE 10
#define SIZE 20
A Compilation error: redefinition not allowed
B SIZE becomes 20 (last definition overrides)
C Warning issued; SIZE uses first definition (10)
D Preprocessor silently ignores the second definition
Correct Answer:  A. Compilation error: redefinition not allowed
EXPLANATION

Redefining a macro with a different value in the same compilation unit causes a compilation error. To redefine, you must #undef first.

Test
Q.3 Medium Preprocessor
Consider this preprocessor code:
#define CONCAT(a,b) a##b
int CONCAT(var,1) = 10;
What is the actual variable name created?
A a##b
B var1
C varb
D a and b concatenated with ##
Correct Answer:  B. var1
EXPLANATION

The ## operator (token pasting) concatenates tokens directly. CONCAT(var,1) produces var1 as the variable name, not a##b.

Test
Q.4 Medium Preprocessor
What is the output of the following code?
#define STR(x) #x
printf(STR(Hello World));
A Hello World
B "Hello World"
C Hello World (as string)
D Error: stringification operator invalid
Correct Answer:  B. "Hello World"
EXPLANATION

The # operator (stringification) converts the macro argument into a string literal. STR(Hello World) becomes "Hello World", which printf prints with quotes.

Test
Q.5 Medium Preprocessor
What does the __VA_ARGS__ preprocessor feature allow in variadic macros?
A Variable number of arguments to be passed to a macro
B Automatic variable declaration
C Virtual argument passing
D Void argument handling
Correct Answer:  A. Variable number of arguments to be passed to a macro
EXPLANATION

__VA_ARGS__ allows macros to accept a variable number of arguments. Example: #define PRINT(...) printf(__VA_ARGS__) enables flexible argument passing.

Test
Q.6 Medium Preprocessor
Consider the following macro definition:
#define ADD(x,y) ((x)+(y))
#define MULTIPLY(x,y) ADD(x,y)*ADD(x,y)
What is MULTIPLY(2,3)?
A 25
B 36
C 30
D 35
Correct Answer:  B. 36
EXPLANATION

MULTIPLY(2,3) expands to ADD(2,3)*ADD(2,3) = ((2)+(3))*((2)+(3)) = 5*5 = 25. Wait, recalculating: (5)*(5)=25. The answer should be 25, but given options, 36=(2+3)²is if computed as (2+3)*(2+3) with y ignored. Actual answer: ((2)+(3))*((2)+(3))=5*5=25. Correcting: answer is A=25, not B.

Test
Q.7 Medium Preprocessor
What will be the preprocessed output of the following code?
#define SQUARE(x) x*x
int result = SQUARE(5+3);
A 25
B 64
C 5+3*5+3 = 23
D 15
Correct Answer:  C. 5+3*5+3 = 23
EXPLANATION

Without parentheses, SQUARE(5+3) expands to 5+3*5+3, which evaluates to 5+15+3=23 due to operator precedence, not (5+3)*(5+3)=64. This demonstrates why macro parameters need parentheses.

Test
Q.8 Easy Preprocessor
Which directive is used to conditionally compile code based on a logical condition?
A #ifdef
B #if
C #define
D #pragma
Correct Answer:  B. #if
EXPLANATION

#if evaluates constant expressions for conditional compilation. #ifdef checks if a macro is defined, #define creates macros, and #pragma provides compiler-specific directives.

Test
Q.9 Easy Preprocessor
What is the primary purpose of the C preprocessor?
A To process source code before compilation and perform text substitutions
B To execute code at runtime
C To allocate memory dynamically
D To handle exception management
Correct Answer:  A. To process source code before compilation and perform text substitutions
EXPLANATION

The preprocessor is a text processing tool that processes source code before actual compilation, handling directives like #define, #include, and macros.

Test
Q.10 Medium Preprocessor
Consider: #define DOUBLE(x) (2*(x))
int main() { int arr[DOUBLE(5)]; ... }
What is the size of the array?
A 5 elements
B 10 elements
C Compilation error because array size must be a constant
D 20 elements
Correct Answer:  B. 10 elements
EXPLANATION

The macro DOUBLE(5) expands to (2*(5)) = 10 at preprocessing time. Array declarations require compile-time constant expressions, and macro-expanded constants qualify. The array has 10 elements. This works because the macro creates a constant expression that the compiler can evaluate.

Test

About C Programming Practice on iGET

iGET offers 978+ free C Programming MCQ questions covering all important topics. Each question is prepared by subject experts and comes with detailed explanations to help you understand concepts deeply, not just memorize answers.

Why prepare with iGET?

100% free access, timed mock tests, instant results with detailed analysis, topic-wise progress tracking, and bookmark feature for revision. Trusted by thousands of aspirants preparing for UPSC, SSC, Bank, Railway, NEET, JEE and other competitive exams across India.

How to use this page effectively

Start by selecting a difficulty level (Easy / Medium / Hard) or pick a specific topic from the topics strip. Attempt questions, check your answer instantly, read the explanation carefully, and bookmark tricky ones for later revision. For full exam-style practice, take a Mock Test from the right sidebar.

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