retagged by
1,694 views
2 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

2 Answers

Best answer
3 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 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:
Position:
Show:

Related questions

2 2 votes
3 3 answers
1.2k
1.2k views
go_editor asked Dec 30, 2016
1,213 views
In the code fragment given below, $\mathsf{start}$ and $\mathsf{end}$ are integer values and $\mathsf{prime(x)}$ is a function that returns $\mathsf{true}$ if $\mathsf{x}...
2 2 votes
2 answers 2 answers
1.3k
1.3k views
go_editor asked Dec 30, 2016
1,304 views
ScamTel has won a state government contract to connect $17$ cities by high-speed fibre optic links. Each link will connect a pair of cities so that the entire network is ...
2 2 votes
2 2 answers
1.7k
1.7k views
go_editor asked Dec 30, 2016
1,656 views
An advertisement for a tennis magazine states, "If I'm not playing tennis, I'm watching tennis. And If I'm not watching tennis, I'm reading about tennis." We can assume t...
5 5 votes
2 2 answers
1.1k
1.1k views
go_editor asked Dec 30, 2016
1,148 views
Varsha lives alone and dislikes cooking, so she goes out for dinner every evening. She has two favourite restaurants, $\text{Dosa Paradise}$ and $\text{Kababs Unlimited}$...