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)); }- A. Prints 10, static just restricts later files from seeing compute
- B. Compile error: static declaration of 'compute' follows non-static declaration
- C. Linker error: undefined reference to compute
- 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
- What is printed? c int a[] = {10, 20, 30, 40, 50}; printf("%d", a[1, 3]);
- What can be said about this program? c int main(void) { int arr[5]; arr[5] = 10; printf("%d", arr[5]); }
- What is the only output consistent with the C standard? c int a[3] = {10, 20, 30}; int p = a; printf("%d %d", p++, p);
- What is printed? c int x = 5; x = x++ + 1; printf("%d", x);
- What is printed? c int i, j; for (i = 0, j = 10; i < 3; i++, j--) ; printf("%d %d", i, j);
- What is printed? Assume 32-bit int, two's complement. c unsigned int a = 5, b = 9; a = a ^ b; b = a ^ b; a = a ^ b; printf("%u %u", a, b);