What will be the output of this code?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
int myregister int x, register int y)
{
static int i;
for(i = 0; i < i; i++)
{
x += 2;
y += 2;
}
}
What will be the output of this code?
Show answer & explanation
Answer: D. Compile time error
The function declaration has a syntax error: int myregister int x, register int y) is missing the opening parenthesis after myregister. This is a malformed function declaration that will cause the compiler to fail during the compilation phase. The code will not compile, so no runtime output is possible.
Step-by-step Derivation:
Step-by-step analysis:
- Parse the function declaration:
int myregister int x, register int y) - Expected syntax:
int myregister(int x, register int y) - Missing opening parenthesis
(after function namemyregister - The compiler encounters an unexpected token
intwhere it expects(, raising a syntax error - Compilation fails before any runtime execution
- Result: Compile time error
Note: Even if the syntax were corrected, the loop condition i < i would always be false (0 < 0 is false), so the loop body would never execute, and the function would return without output.