ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
void outerFunc(void) {
    int x = 10;
    {
        int y = 20;
        printf("%d %d ", x, y);
    }
    // printf("%d", y); // line X
}
int main(void) { outerFunc(); }
What happens if line X is uncommented?
  1. A. Compilation error: y is out of scope outside the block in which it was declared
  2. B. It compiles and prints 0
  3. C. It compiles and prints a garbage value
  4. D. It compiles fine and prints 20 again

Correct answer: A. Compilation error: y is out of scope outside the block in which it was declared

y's scope is limited to the inner block {}; once that block ends, y no longer exists as a visible identifier — referencing it afterward is a compile-time 'undeclared identifier' error, not a run-time issue.

More C Programming questions

Exams that ask this topic