Q: 1 What is the value of y after executing the following code?
#define square(p) p*p
void main()
{
int y=square(2+3);
printf("%d",y);
}
13
25
11
Illegal Expression
[ Option C ]
In this program, square(p) is defined as a macro. A macro in C works by simple text substitution, meaning the compiler directly replaces the macro with its definition without adding any extra brackets.
When the statement square(2+3) is written, it is replaced by 2+3*2+3. According to operator precedence rules, multiplication has higher priority than addition, so 3*2 is evaluated first. This makes the expression 2+6+3, which results in the value 11.
Q: 2 The preprocessors in C are defined with ________________ character.
/
#
*
$
[ Option B ]
In C programming, Preprocessor Directives are lines included in the code that are processed before compilation. These directives always begin with the # (Hash) symbol. Examples of commonly used preprocessor directives starting with # include, #define, #ifdef, #ifndef etc.
| PREPROCESSOR DIRECTIVE | DESCRIPTION |
|---|---|
| #include | Includes standard or user-defined header files in the program. |
| #define | Defines a macro or symbolic constant. |
| #undef | Undefines a previously defined macro. |
| #ifdef | Checks if a macro is defined, includes code if true. |
| #ifndef | Checks if a macro is not defined, includes code if true. |
| #if | Tests a compile-time condition, includes code if true. |
| #else | Specifies alternative code if #if or #ifdef condition is false. |
| #elif | Combines else and if in conditional compilation. |
| #endif | Ends the conditional directive started by #if, #ifdef, #ifndef. |
| #error | Generates a compilation error with a message. |
| #pragma | Provides special instructions to the compiler. |
| #line | Changes the reported line number and filename for errors. |
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.