ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
int x = 5;
void modify(void) {
    x = 10;
}
int main(void) {
    int x = 20;
    modify();
    printf("%d %d", x, ::x == 5);
}
  1. A. 20 1
  2. B. 10 1
  3. C. 20 0
  4. D. Compile-time error: :: is not a C operator

Correct answer: D. Compile-time error: :: is not a C operator

The scope-resolution operator :: exists in C++ to reach a shadowed global, but C has no such operator at all; using ::x in plain C source is a syntax error, so this fails to compile (this is a classic trap for people switching between C and C++).

More C Programming questions

Exams that ask this topic