Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

15. Given four statements below determine which statement combination is correct

ID: 3736184 • Letter: 1

Question

15. Given four statements below determine which statement combination is correct 1. If a variable is declared as an extern in one file ther the variable is 2. A global variable that is declared in a file as a static (e.g., static 3. A static variable in a block of code car appear only once in a program a global variable int numCourses) is only visible to the functions in the file pg. 5 4. A block of code can have only one static variable A. statement 1 is true and s B. Statement 2 is true and statement 4 is not true C. Statement 2 is true and statement 1 is not true D. statement 3 is true and statement 3 is not txue E. None of the above tatement 3 is true

Explanation / Answer

Explanation:

1) An external variable can be accessed by all the functions in all the modules of a program. It is a global variable. For a function to be able to use the variable, a declaration or the definition of the external variable must lie before the function definition in the source code.

2) Static variables at file level are invisible to anything outside the translation unit (the linker can't see it.

3) static variable is initialized only once no matter how many times the function in which it resides is called and its value is retained and accessible through many calls to the function in which it is declared. however, there is no restriction on the number of appearance in the program.

4)A block can have any number of static variables

Hence statement 1 and 2 is true while 3 and 4 is not true.

Option B is correct.
!! feel free to ask doubts !! :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote