Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 21–30 of 291
Topics in C Programming
Q.21 Easy Preprocessor
Which preprocessor directive is used to conditionally compile code based on whether a macro is defined?
A #if
B #ifdef
C #ifndef
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

#ifdef checks if a macro is defined, #ifndef checks if it's not defined. Both are used for conditional compilation based on macro definition status.

Test
Q.22 Easy Preprocessor
Which of the following is NOT a preprocessor directive?
A #include
B #define
C #pragma
D #allocate
Correct Answer:  D. #allocate
EXPLANATION

#allocate is not a valid preprocessor directive. Valid directives include #include, #define, #pragma, #ifdef, #ifndef, #if, #else, #elif, #endif, #error, #undef.

Test
Q.23 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.

Test
Q.24 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.

Test
Q.25 Easy Preprocessor
What is the output?
#define MAX(a,b) (a>b?a:b)
printf("%d", MAX(10, 5));
A 10
B 5
C Error
D 15
Correct Answer:  A. 10
EXPLANATION

The macro expands to (10>5?10:5) which evaluates to 10 since the condition is true.

Test
Q.26 Easy Preprocessor
What does the following preprocessor directive do?
#define SQUARE(x) ((x)*(x))
A Defines a function named SQUARE
B Defines an object-like macro
C Defines a function-like macro
D Creates a compilation error
Correct Answer:  C. Defines a function-like macro
EXPLANATION

This is a function-like macro that takes parameter x and expands to ((x)*(x)). The parentheses around x prevent operator precedence issues.

Test
Q.27 Easy Preprocessor
Which preprocessor directive is used to include standard library files?
A #include
B #include "filename"
C Both A and B
D #import
Correct Answer:  C. Both A and B
EXPLANATION

#include <filename> is used for standard library files (searched in standard paths). #include "filename" is used for user-defined header files (searched in current directory first).

Test
Q.28 Easy Preprocessor
What is the output of the following code?
#define MAX 5
int arr[MAX];
A Compilation error
B Array of size 5 is created
C Runtime error
D Preprocessor error
Correct Answer:  B. Array of size 5 is created
EXPLANATION

The preprocessor replaces MAX with 5, creating an array of size 5. This is a valid use of macro expansion.

Test
Q.29 Easy Preprocessor
Which of the following is NOT a preprocessor directive in C?
A #define
B #include
C #pragma
D #declare
Correct Answer:  D. #declare
EXPLANATION

#declare is not a valid preprocessor directive. Valid directives include #define, #include, #pragma, #ifdef, #endif, #if, #else, etc.

Test
Q.30 Easy Dynamic Memory
In implementing a dynamic doubly-linked list, what additional field is required compared to singly-linked list?
A Data field
B Previous pointer
C Size field
D Head pointer
Correct Answer:  B. Previous pointer
EXPLANATION

Doubly-linked list nodes require both next and previous pointers to enable bidirectional traversal unlike singly-linked lists.

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