C Programming
C language from basics to advanced placement prep
303 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 303 questions
Q.1 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.

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

Take Test
Q.3 Easy Preprocessor
What is the purpose of defined() operator in preprocessor conditionals?
A To check if a macro is defined
B To define a new macro conditionally
C To undefine a macro
D To check if a variable is initialized
Correct Answer:  A. To check if a macro is defined
EXPLANATION

defined(MACRO) is used in #if and #elif directives to test if a macro is defined. Example: #if defined(DEBUG) ... #endif. It's equivalent to #ifdef but can be used in expressions with logical operators like && and ||.

Take Test
Q.4 Easy Preprocessor
What happens when #if 0...#endif wraps a block of code?
A The code is compiled but not executed
B The code is completely ignored by the preprocessor and not compiled
C It causes a compilation error
D The code is commented out
Correct Answer:  B. The code is completely ignored by the preprocessor and not compiled
EXPLANATION

#if 0...#endif is used to disable code during preprocessing. The enclosed code is skipped entirely and doesn't appear in the compiled output. This is more efficient than C-style comments for large blocks and maintains nested comment compatibility.

Take Test
Q.5 Easy Preprocessor
What is the difference between #include and #include "file.h"?
A Both search in the same directories
B searches system paths first; "" searches current directory first
C "" is only for local files, for system files
D There is no functional difference; both are equivalent
Correct Answer:  B. searches system paths first; "" searches current directory first
EXPLANATION

#include <file.h> searches in standard system include directories. #include "file.h" searches in the current working directory first, then system directories. This allows you to override system headers with local versions.

Take Test
Advertisement
Q.6 Easy Preprocessor
Which header file is required to use assert() macro in C?
A assert.h
B stdlib.h
C stdio.h
D error.h
Correct Answer:  A. assert.h
EXPLANATION

assert.h contains the assert() macro which is useful for debugging. It tests a condition and aborts the program if the condition is false. This macro is only active when NDEBUG is not defined.

Take Test
Q.7 Easy Preprocessor
In C99, which of the following is a valid use of token pasting operator (##)?
A #define CONCAT(a,b) a##b
B #define CONCAT(a,b) a ## b
C #define CONCAT(a,b) a## ##b
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

Both options A and B are valid. The ## operator pastes two tokens together. Whitespace around ## doesn't matter. #define CONCAT(a,b) a##b could be used as CONCAT(var, 1) to create var1.

Take Test
Q.8 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
Q.9 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.10 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