What is a macro in C?
A
A runtime variable B
A compile-time function C
A keyword D
A preprocessor directive
Analysis & Theory
Macros are preprocessor directives defined using `#define`, replaced before compilation.
Which symbol is used to define a macro in C?
A
$ B
# C
& D
@
Analysis & Theory
`#define` is used to define a macro in C.
What does this macro do?
```c
#define PI 3.14
```
A
Defines a variable B
Defines a constant PI C
Defines a function D
Creates a header
Analysis & Theory
This macro replaces every occurrence of `PI` with `3.14` before compilation.
What is the result of this macro?
```c
#define SQUARE(x) x * x
```
A
Returns x squared B
Returns an error C
Works only for integers D
Incorrect for expressions
Analysis & Theory
`SQUARE(x)` without parentheses can give wrong results for expressions like `SQUARE(1+2)` → 1+2*1+2 = 5.
How do you avoid operator precedence issues in macro functions?
A
Use `const` B
Use parentheses in macro definition C
Use `inline` D
Use typedef
Analysis & Theory
Always wrap parameters and the entire expression in parentheses.
Which of the following is a conditional compilation macro?
A
#if B
#for C
#macro D
#when
Analysis & Theory
`#if`, `#ifdef`, and `#ifndef` are used for conditional compilation.
What does `#undef` do in C?
A
Uninstalls a macro B
Deletes a variable C
Removes macro definition D
Clears memory
Analysis & Theory
`#undef MACRO` removes the definition of a previously defined macro.
What is the purpose of `#ifndef` in header files?
A
To define macros B
To prevent multiple inclusion C
To compile code faster D
To define constants
Analysis & Theory
`#ifndef` prevents double inclusion of the same header file (include guards).
Which is true about macros and functions?
A
Macros are slower than functions B
Macros are evaluated at runtime C
Macros do not have type checking D
Macros use less memory
Analysis & Theory
Macros are just text replacement; no type checking is done.
Which of the following is **not** a valid macro use?
A
#define MAX 100 B
#define SQR(x) ((x)*(x)) C
#define while if D
#define int float
Analysis & Theory
`#define int float` can lead to very unpredictable and dangerous behavior in your program.