ProgrammingVery hardProduct-company MCQ pattern

What happens when this is compiled?

What happens when this is compiled?
int compute(int x);
static int compute(int x) { return x * 2; }
int main(void) { printf("%d", compute(5)); }
  1. A. Prints 10, static just restricts later files from seeing compute
  2. B. Compile error: static declaration of 'compute' follows non-static declaration
  3. C. Linker error: undefined reference to compute
  4. D. Prints 10 with a compiler warning only

Correct answer: B. Compile error: static declaration of 'compute' follows non-static declaration

The first declaration int compute(int x); gives compute external linkage (the default for functions). Redeclaring it static later for the same identifier tries to downgrade it to internal linkage, which the standard disallows as a conflicting declaration — gcc reports exactly this error.

More C Programming questions

Exams that ask this topic