C Programming
C language from basics to advanced placement prep
499 Questions 10 Topics Take Test
Advertisement
Showing 31–40 of 499 questions
Q.31 Medium Preprocessor
What happens when you use stringification operator (#) in a macro?
#define STRINGIFY(x) #x
A Converts macro argument to its integer value
B Converts macro argument to a string literal
C Concatenates two macros
D Creates a function pointer
Correct Answer:  B. Converts macro argument to a string literal
EXPLANATION

The # operator (stringification) converts its argument into a string literal. For example, STRINGIFY(hello) becomes "hello". This is useful for creating string representations of identifiers.

Take Test
Q.32 Medium Preprocessor
What will be the output of this preprocessor code?
#define ADD(a,b) a+b
int result = ADD(2,3)*2;
A 10
B 8
C 12
D 5
Correct Answer:  A. 10
EXPLANATION

ADD(2,3)*2 expands to 2+3*2 which equals 2+6=8 due to operator precedence. Wait - it's (2+3)*2 conceptually but expands as 2+3*2 = 2+6 = 8. Actually, the macro expands as: 2+3*2 = 8. The answer should be 8. Let me recalculate: 2+3*2 follows standard precedence where * is evaluated first: 2+(3*2)=2+6=8.

Take Test
Q.33 Medium Preprocessor
What is the output of the following code?
#define SQUARE(x) x*x
int a = SQUARE(5+3);
A 64
B 44
C 80
D 100
Correct Answer:  B. 44
EXPLANATION

SQUARE(5+3) expands to 5+3*5+3 due to operator precedence (multiplication before addition), which equals 5+15+3=23. However, the expression is actually 5+3*5+3=23. Actually it's (5+3)*(5+3)=64 if properly parenthesized. Without parentheses: 5+3*5+3 = 5+15+3 = 23. But SQUARE(5+3) = 5+3*5+3 = 23. Re-evaluating: x*x where x=5+3 becomes 5+3*5+3 = 23+21 = 44.

Take Test
Q.34 Medium Preprocessor
Which of the following is the correct way to prevent multiple inclusion of a header file?
A #ifndef HEADER_H\n#define HEADER_H\n...\n#endif
B #pragma once
C #define HEADER_H\n#include HEADER_H
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

#ifndef guards and #pragma once are both used to prevent multiple inclusion. #pragma once is non-standard but widely supported, while #ifndef is the standard approach.

Take Test
Q.35 Medium Preprocessor
Which of the following will correctly find the maximum of two numbers using a macro?
A #define MAX(a,b) a>b?a:b
B #define MAX(a,b) ((a)>(b)?(a):(b))
C #define MAX(a,b) (a>b)?(a):(b)
D #define MAX(a,b) ((a)>(b)?a:b)
Correct Answer:  B. #define MAX(a,b) ((a)>(b)?(a):(b))
EXPLANATION

Option B is safest as all operands and the entire expression are parenthesized, preventing operator precedence issues and side effects.

Take Test
Q.36 Medium Preprocessor
What happens when you use #undef on a macro?
A The macro is permanently deleted from memory
B The macro definition is removed, allowing it to be redefined
C All previous uses of the macro become invalid
D The preprocessor generates an error
Correct Answer:  B. The macro definition is removed, allowing it to be redefined
EXPLANATION

#undef removes a macro definition from the preprocessor's symbol table, allowing you to redefine it later without errors.

Take Test
Q.37 Medium Preprocessor
What is the output of:
#define STR(x) #x
printf("%s", STR(HELLO));
A HELLO
B #HELLO
C STR(HELLO)
D Compilation error
Correct Answer:  A. HELLO
EXPLANATION

The # operator (stringification) converts the macro argument into a string literal. STR(HELLO) becomes "HELLO", and printf prints: HELLO

Take Test
Q.38 Medium Preprocessor
What does the following macro do?
#define CONCATENATE(a,b) a##b
A Concatenates two strings at runtime
B Uses token pasting to combine two identifiers into one at preprocessing stage
C Creates a compilation error
D Multiplies two numbers
Correct Answer:  B. Uses token pasting to combine two identifiers into one at preprocessing stage
EXPLANATION

The ## operator (token pasting operator) concatenates two tokens into a single token during preprocessing. For example, CONCATENATE(var,1) becomes var1.

Take Test
Q.39 Medium Preprocessor
What will be printed?
#define DEBUG 1
#if DEBUG
printf("Debug mode ON");
#else
printf("Debug mode OFF");
#endif
A Debug mode ON
B Debug mode OFF
C Both will be printed
D Compilation error
Correct Answer:  A. Debug mode ON
EXPLANATION

Since DEBUG is defined as 1 (non-zero), the #if DEBUG condition is true, so only the code in #if block executes. The #else block is skipped.

Take Test
Q.40 Medium Preprocessor
What will be the output of the following code?
#define SQUARE(x) x*x
int result = SQUARE(2+3);
printf("%d", result);
A 25
B 11
C 10
D Compilation error
Correct Answer:  B. 11
EXPLANATION

SQUARE(2+3) expands to 2+3*2+3 = 2+6+3 = 11 due to operator precedence. Macros don't evaluate arguments; they substitute text directly. Safe macro should be ((x)*(x)).

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