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);
}- A. 20 1
- B. 10 1
- C. 20 0
- 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
- What is printed? c static int helper(int x) { return x 2; } int main(void) { printf("%d", helper(5)); }
- What is printed? c void outer(void) { int x = 1; void inner(void) { printf("%d", x); } inner(); } int main(void) { outer(); }
- What happens at link time? c // file1.c static int counter = 0; void increment(void) { counter++; } c // file2.c (compiled and linked with…
- What is printed? c int x = 10; void foo(void) { int x = 20; { int x = 30; printf("%d ", x); } printf("%d ", x); } int main(void) { foo()…
- What is printed? c void f(void) { int x = 5; x = x++ + ++x; printf("%d", x); } int main(void) { f(); }
- What is printed? c int f(void) { printf("f "); return 1; } int g(void) { printf("g "); return 0; } int main(void) { if (g() && f())…