If malloc() returns NULL, what should a program do?
Answer: B
NULL return from malloc indicates allocation failure; ignoring causes dereferencing NULL which leads to crash.
Q.262Easy
In implementing a dynamic doubly-linked list, what additional field is required compared to singly-linked list?
Answer: B
Doubly-linked list nodes require both next and previous pointers to enable bidirectional traversal unlike singly-linked lists.
Q.263Easy
Which of the following is NOT a preprocessor directive in C?
Answer: D
#declare is not a valid preprocessor directive. Valid directives include #define, #include, #pragma, #ifdef, #endif, #if, #else, etc.
Q.264Easy
What is the output of the following code?
#define MAX 5
int arr[MAX];
Answer: B
The preprocessor replaces MAX with 5, creating an array of size 5. This is a valid use of macro expansion.
Q.265Easy
Which preprocessor directive is used to include standard library files?
Answer: C
#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).
Advertisement
Q.266Easy
What does the following preprocessor directive do?
#define SQUARE(x) ((x)*(x))
Answer: C
This is a function-like macro that takes parameter x and expands to ((x)*(x)). The parentheses around x prevent operator precedence issues.
Q.267Easy
What is the output?
#define MAX(a,b) (a>b?a:b)
printf("%d", MAX(10, 5));
Answer: A
The macro expands to (10>5?10:5) which evaluates to 10 since the condition is true.
Q.268Easy
What is the purpose of the #undef directive?
Answer: A
#undef is used to remove the definition of a macro so it cannot be used in subsequent code.
Q.269Easy
What is the primary role of the C preprocessor in the compilation process?
Answer: A
The preprocessor is a separate program that processes source code before the compiler. It handles directives like #include, #define, and #ifdef.
Q.270Easy
Which of the following is NOT a preprocessor directive?
Answer: D
#allocate is not a valid preprocessor directive. Valid directives include #include, #define, #pragma, #ifdef, #ifndef, #if, #else, #elif, #endif, #error, #undef.
Q.271Easy
Which preprocessor directive is used to conditionally compile code based on whether a macro is defined?
Answer: D
#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.
Q.272Easy
Which statement about preprocessor is TRUE?
Answer: B
Preprocessor directives (starting with #) are processed before the actual compilation by a separate preprocessor tool. They perform text substitution and conditional compilation.
Q.273Easy
Which preprocessor directive should be used to check if a macro is NOT defined?
Answer: D
Both #ifndef and #if !defined(MACRO) are equivalent and check if a macro is not defined. #ifndef is simpler syntax for this specific case.
Q.274Easy
Which header file is included using angle brackets in standard C library?
Answer: B
Standard library headers like stdio.h, stdlib.h, string.h are included using angle brackets #include <filename>.
Q.275Easy
Which preprocessor directive is used to define a constant that cannot be changed during program execution?
Answer: A
#define is used to create macro definitions and constants at compile time. #const, #constant, and #fixed are not valid preprocessor directives in C.
Q.276Easy
Which of the following is a difference between #include <file.h> and #include "file.h"?
Answer: D
The angle bracket version searches in standard system directories first, while quoted version searches in the current/local directory first. Both statements B and C correctly describe this distinction.
Q.277Easy
Consider the following code:
#define PI 3.14
#undef PI
#define PI 3.14159
What is the value of PI after execution?
Answer: B
#undef removes the previous definition of PI. The subsequent #define redefines PI as 3.14159. This is valid C syntax and the final value of PI is 3.14159.
Q.278Easy
Which header file must be included to use the NULL macro?
Answer: D
NULL is defined in multiple standard headers including <stdio.h>, <stdlib.h>, <stddef.h>, <string.h>, and others. Any of these can be included to use NULL.
Q.279Easy
Which of the following correctly demonstrates the use of conditional compilation?
Answer: A
Option A uses #ifdef to check if DEBUG is defined, which is correct for conditional compilation. Option B would check if DEBUG has a non-zero value (expression-based). Options C and D have invalid syntax.
Q.280Easy
What is the output of the following code?
#define PI 3.14
int main() { printf("%f", PI); return 0; }
Answer: C
PI is replaced by 3.14 during preprocessing. When printed with %f format specifier, it displays as 3.140000 (default 6 decimal places).