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)? The scope of a variable is contained in the lifetime of the variable The scope of a variable is same as the lifetime of the variable The lifetime of a variable is disjoint from the scope of the variable None of the above Programming in C cmi2016 programming-in-c scoping-rule lifetime + – go_editor asked Dec 30, 2016 retagged Nov 8, 2019 by Lakshman Bhaiya go_editor 1.2k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
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 Lokesh . answered Dec 30, 2016 selected Dec 30, 2016 by srestha Lokesh . comment Share Follow See 1 comment See all 1 1 comment reply ChayAdhiraj commented May 18, 2022 reply Follow Share 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. 0 votes 0 votes Please log in or register to add a comment.
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. ChayAdhiraj answered May 18, 2022 ChayAdhiraj comment Share Follow See all 0 reply Please log in or register to add a comment.