ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
static int helper(int n) { return n * 2; }
int main(void) { printf("%d", helper(5)); }
  1. A. Compilation error: static functions cannot be called from main
  2. B. 10, static here just restricts linkage to this translation unit
  3. C. 0, static functions return 0 by default
  4. 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

Exams that ask this topic