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

Declarations and Initializations Questions and Answers

31.

Is the following statement a declaration or definition?
extern int i;

Answer: A

Correct answer: Declaration

extern int i; announces that an object named i of type int exists somewhere, without reserving storage for it. A definition is what allocates the storage, and there must be exactly one of those in the program however many declarations refer to it.

Please log in or register to report this question.

32.

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?

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.

Please log in or register to report this question.

Loading…
Tags: Declarations and Initializations Questions and Answers || Declarations and Initializations MCQ Questions and Answers || Declarations and Initializations GK Questions and Answers || Declarations and Initializations GK MCQ Questions || Declarations and Initializations Multiple Choice Questions and Answers || Declarations and Initializations GK || GK on Declarations and Initializations || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming