Machine-translated by Google. Questions are authored in English.
Top

Discussion

Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need the extern declaration for the variables in the files f2 and f3?

  • A.Yes
  • B.No

Answer: A

Correct answer: Yes

The definition lives in one file and reserves the storage; the other two files must be told that the name exists and what type it has, or the compiler has nothing to check their uses against. That is precisely what extern does, and the declaration is conventionally put in a header included by both.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.