ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
static int helper(int x) { return x * 2; }
int main(void) {
printf("%d", helper(5));
}- A. 10
- B. Compile-time error: static functions cannot be called from main
- C. 5
- D. Linker error: helper has internal linkage and cannot be called
Correct answer: A. 10
static on a FUNCTION (not inside a function body) simply gives it internal linkage, confining its visibility to this translation unit — it does not restrict who within that same file can call it. main() is in the same file, so calling helper(5) is perfectly normal, returning 10.
More C Programming questions
- 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())…
- What is printed? c int f(void) { printf("f "); return 1; } int g(void) { printf("g "); return 1; } int main(void) { if (f() || g())…