Question 4
Back to Exercise
This program compiles without errors but cannot be built into an executable. Why?
#include <stdio.h>
extern int max_users;
int main(void) {
printf("%d\n", max_users);
return 0;
}
- A extern cannot be used with int
- B extern only declares max_users; no file defines it, so the linker reports an undefined symbol Correct
- C max_users must be initialised in main()
- D There is no bug; it prints 0
Correct Answer: Option B
The compiler trusts the declaration; the linker then finds no definition anywhere ("Undefined symbols … _max_users" / "undefined reference to max_users"). Add exactly one definition, e.g. int max_users = 100; in one .c file.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!