retagged by
1,197 views
2 votes
2 votes

Which of the following relationships holds in general between the $\text{scope}$ of a variable and the $\text{lifetime}$ of a variable (in a language like C or Java)?

  1. The scope of a variable is contained in the lifetime of the variable
  2. The scope of a variable is same as the lifetime of the variable
  3. The lifetime of a variable is disjoint from the scope of the variable
  4. None of the above
retagged by

2 Answers

Best answer
3 votes
3 votes

Scope of a variable is the visibility of the variable within function or statement block.
(ex. local variable is visible within a specific block and global variable is visible everywhere)

Lifetime of a variable is time period for which it has a valid memory location.

so ans should be Option C

selected by
0 votes
0 votes
Answer should be (B).

The lifetime of a variable ends when it is out of scope.

Moreover, the scope of a variable is always same throughout its lifetime.

Thus the scope of a variable is same as its lifetime.
Answer:

Related questions

3 votes
3 votes
2 answers
2
sunil sarode asked Nov 4, 2017
2,132 views
Choose the False statements:(a) The scope of a macro definition need not be the entire program(b) The scope of a macro definition extends from the point of definition to ...
1 votes
1 votes
2 answers
3