OA. free
Free
Qualcomm Embedded Systems & Hardware Embedded Systems & Hardware Medium

What will be the output of the program given below?

Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.

What will be the output of the program given below?

#include <stdio.h>

int main()
{
    int x = 1;
    {
        int y = 2;
    }
    printf("%d %d ", x, y);
    return 0;
}
Choose one option.
Show answer & explanation
Answer: C. Compile time error

The variable y is declared inside an inner block (scope) with int y = 2;. Once that block ends, y goes out of scope and is no longer accessible. When printf() tries to reference y outside its block, the compiler cannot find the variable declaration, resulting in a compile-time error: 'undefined reference to y' or similar.

Step-by-step Derivation:
Step-by-step analysis:

  1. int x = 1; declares x in main's scope—valid.
  2. { int y = 2; } creates an inner block where y is declared with block scope.
  3. After the closing brace }, y is out of scope and no longer exists.
  4. printf("%d %d ", x, y); attempts to use y, but y is not visible in main's scope.
  5. Compiler error: y is undeclared at this point.
  6. The program will NOT compile; it will produce a compile-time error.