WEBVTT

00:00.520 --> 00:09.100
So in the last lecture we went over the concept called scope and he said the scope of declaration is

00:09.100 --> 00:15.790
the part of the program for which the variable or identifier is accessible.

00:15.790 --> 00:24.730
So today I want to talk about lifetime which is sort of a similar concept to scope and the lifetime

00:24.750 --> 00:30.190
a variable is the time period in which the variable has valid memory.

00:30.610 --> 00:39.880
So the lifetime of x rays here is just the amount of time that phunk is active.

00:39.940 --> 00:46.450
So when x is defined initialized the memory is for x is valid.

00:46.660 --> 00:56.500
And as soon as phunk is finished say in line 18:3 here then X is automatically destroyed so the memory

00:56.500 --> 00:58.990
is not valid anymore.

00:59.140 --> 01:07.560
Ducey can't use X anymore after func there's just the memory is just not there for it anymore.

01:07.630 --> 01:13.410
So if an X was declared outside of any function.

01:13.720 --> 01:22.130
So it was a global variable then the lifetime of x would be how long the program runs itself.

01:22.150 --> 01:30.540
So just it would be the entire run of the program so interestingly if you think about it if you had

01:30.570 --> 01:37.980
a variable in the main function then its lifetime would also be the entire run of the program.

01:38.010 --> 01:44.190
Since Maine is the very first function that is called in your program it will be the last function to

01:44.190 --> 01:51.740
exit so however its scope is only the main function and remember.

01:52.080 --> 01:58.290
So we'll be using this fact to our advantage in our games and we'll talk about lifetime a little bit

01:58.290 --> 01:59.700
more later.
