What is the difference between lifetime and scope




















The lifetime of a variable or function is the time duration for which memory is allocated to store it, and when that memory is released. It also refered as extent of a variable. The scope and lifetime of a variable are central design issues which defines the interaction between data and functions. A variable declared within a function has a local scope by default.

This means that it is visible only to the block in which it is defined. A variable defined outside of any function is an external variable, by default. Scope for these variable is called external scope or program scope. The value persists even between function calls. The life time is entire execution of the program. Posted by bloggie at Email This BlogThis!

Labels: C interview Questions , life time , scope. Post your learning requirement. Looking for BTech Tuition Classes? About UrbanPro. I am a Student I am a Tutor. Please enter your full name. Please enter institute name. Please enter your email address. Please enter a pincode or area name. Please enter city name. Please enter category. Male Female Please select your gender. Please enter either mobile no.

A variable which is declared inside a class, but is declared outside any methods and blocks is known as instance variable. Scope: Throughout the class except in the static methods. Lifetime: Until the object of the class stays in the memory. A variable which is declared inside a class, outside all the blocks and is declared as static is known as class variable.

Scope: Throughout the class. Lifetime: Until the end of the program.



0コメント

  • 1000 / 1000