ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
static int helper(int n) { return n * 2; }
int main(void) { printf("%d", helper(5)); }- A. Compilation error: static functions cannot be called from main
- B. 10, static here just restricts linkage to this translation unit
- C. 0, static functions return 0 by default
- D. Undefined behavior: static applied to a function is illegal
Correct answer: B. 10, static here just restricts linkage to this translation unit
static on a function (not just a variable) gives it internal linkage, meaning it's only callable from within this same source file — it has no effect on how it executes when called normally, so helper(5) returns 10 as expected.
More C Programming questions
- What is printed? c void f(void) { static int x = 0; x += 10; printf("%d ", x); } int main(void) { for (int i = 0; i < 3; i++) f(); }
- What is printed? c int global = 1; void modify(void) { int global = 2; global++; } int main(void) { modify(); printf("%d", global); }
- 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);