Linkers, Loaders & Executables

In C, what is the effect of defining a function with static (e.g. static int helper(void))?

  1. AThe function does not stay in memory during execution
  2. BThe function is visible only within its file and does not collide with a same-named function in another file
  3. CThe function runs before every other function
Show answer and explanation

Answer: B. The function is visible only within its file and does not collide with a same-named function in another file

Adding static to a function or global variable gives it internal linkage: the symbol is used only inside that file and cannot be referenced from other files. Besides preventing name collisions, it tells the compiler the function cannot be called from elsewhere, which makes optimizations such as inlining and removing unused functions easier.

  • A. The function's code remains in memory throughout execution.
  • B. Correct. It gets internal linkage.
  • C. The order of execution does not change.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. In C, what does writing "extern int count;" mean?
  2. Which statement is correct about files in the ELF format commonly used on Linux and similar systems?
  3. What is in the .text section of an executable?
  4. In C, a global variable written outside any function as "int limit = 100;" is generally placed in which section?
  5. What is a characteristic of the .bss section?