ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int global = 1;
void modify(void) {
int global = 2;
global++;
}
int main(void) {
modify();
printf("%d", global);
}- A. 2
- B. 1
- C. 3
- D. 0
Correct answer: B. 1
modify declares its own local global that shadows the file-scope one entirely within its body; incrementing it only affects the local copy, which disappears when modify returns. The outer global remains 1.
More C Programming questions
- What is printed? c #include <stdio.h> int x; // tentative definition, file scope int x; // another tentative definition, same file int…
- What is printed? c static int x = 5; void f(void); void f(void) { printf("%d", x); } int main(void) { f(); }
- What is printed? c int a = 2, b = 3, c = 4; int r = a + b c - a / b; printf("%d", r);
- What is printed? c int a = 5; int r = a > 3 ? 10 : 20 + 5; printf("%d", r);
- What is printed? c int a = 4; int r = ~a + 1 == -a; printf("%d", r);
- What is printed? c int a = 3, b = 4, c = 5; int r = a + b == c ? 1 : 0; printf("%d", r);