1
00:00:01,460 --> 00:00:03,050
Hey, guys, what's up?

2
00:00:03,530 --> 00:00:07,700
So today we are going to learn one more concept called global variable.

3
00:00:11,680 --> 00:00:13,920
So what are global labor?

4
00:00:14,950 --> 00:00:18,580
So until now, we have only started local variables.

5
00:00:20,560 --> 00:00:21,880
So what are local variables?

6
00:00:22,450 --> 00:00:36,490
So when I ride in demesne and and I ride an X, so X is a local variable because its scope is only this.

7
00:00:37,030 --> 00:00:39,200
I cannot access X here.

8
00:00:39,910 --> 00:00:42,630
For example, see out X and you give me at it.

9
00:00:43,570 --> 00:00:50,680
So local variables are those who are bounded by scope, whose existence is bounded by the scope.

10
00:00:51,310 --> 00:00:58,120
For example, if you create any variable in a loop also then also for example.

11
00:00:58,180 --> 00:00:58,740
And anyway.

12
00:00:59,260 --> 00:01:03,850
So this is local variable because it's the scope is limited.

13
00:01:04,660 --> 00:01:07,090
Now there was a study global variable.

14
00:01:07,750 --> 00:01:15,070
So the scope of global variable is basically its its core base from the starting of the program to the

15
00:01:15,190 --> 00:01:16,020
end of the program.

16
00:01:17,110 --> 00:01:19,270
OK, so it can be accessed anywhere.

17
00:01:21,220 --> 00:01:22,000
For example.

18
00:01:23,730 --> 00:01:33,660
So how to declare that this is a global variable, so I will write in X and then I will write into Mean.

19
00:01:37,770 --> 00:01:44,310
OK, so now here X is a global variable, X is a global variable.

20
00:01:44,760 --> 00:01:45,090
Why?

21
00:01:45,420 --> 00:01:49,650
Because it is not bounded by any curly brackets.

22
00:01:50,550 --> 00:01:50,830
OK.

23
00:01:51,720 --> 00:01:53,340
So it will exist everywhere.

24
00:01:54,000 --> 00:02:01,440
And suppose you want to, let's say the value of access to all the global variable and the value of

25
00:02:01,440 --> 00:02:03,110
global variable is done.

26
00:02:04,170 --> 00:02:08,330
Now I am writing and X is close to 10.

27
00:02:08,790 --> 00:02:10,460
So will this give me either.

28
00:02:11,230 --> 00:02:11,570
No.

29
00:02:11,730 --> 00:02:11,910
Why?

30
00:02:12,510 --> 00:02:16,020
Because this X and this X, they are different.

31
00:02:16,230 --> 00:02:16,460
Why?

32
00:02:16,560 --> 00:02:18,420
Because their scope are different.

33
00:02:19,020 --> 00:02:20,880
X is a local variable.

34
00:02:23,850 --> 00:02:26,430
Whereas this is a global variable.

35
00:02:27,210 --> 00:02:36,150
So if I write C out X so virtual printer then tension with printer or to will be printed.

36
00:02:36,840 --> 00:02:39,930
So answer is 10 will be my output.

37
00:02:41,320 --> 00:02:49,060
So for accessing global variable, I will write see out scope resolution operator and then X.

38
00:02:49,840 --> 00:02:54,580
So this is called Scope Resolution

39
00:02:56,910 --> 00:02:57,600
Operator.

40
00:02:58,990 --> 00:03:03,150
Now if you will print this, then your output will be equal.

41
00:03:04,600 --> 00:03:11,220
OK, so you have to tell the compiler that this I am trying to access a global variable, otherwise

42
00:03:11,220 --> 00:03:12,790
there may be conflict like this.

43
00:03:13,600 --> 00:03:13,770
OK.

44
00:03:13,900 --> 00:03:17,560
So if you write normally it will be a local variable.

45
00:03:18,220 --> 00:03:22,900
And if you want to access the global variable, we will use scope resolution.

46
00:03:23,000 --> 00:03:23,500
Operator.

47
00:03:24,590 --> 00:03:24,880
OK.

48
00:03:25,160 --> 00:03:32,660
You can also change the way of global variable, like X equals X plus two.

49
00:03:33,490 --> 00:03:33,770
OK.

50
00:03:34,130 --> 00:03:37,100
You can also change the value of global variable.

51
00:03:37,730 --> 00:03:38,390
So let's see.

52
00:03:45,380 --> 00:03:50,960
So let's name this as global Nazi BP, so global

53
00:03:53,660 --> 00:03:54,590
Nazi BP.

54
00:04:02,540 --> 00:04:04,070
Now we will right where they were.

55
00:04:04,220 --> 00:04:05,330
We asked China to allow.

56
00:04:16,580 --> 00:04:24,520
So first of all, make a global variable, so and X equals 10, let's say 20.

57
00:04:25,610 --> 00:04:28,070
So X is a global variable here.

58
00:04:28,820 --> 00:04:32,030
Now let us create one local variable.

59
00:04:33,080 --> 00:04:36,740
So and X equals 10.

60
00:04:37,550 --> 00:04:41,540
OK, so this X is a local variable.

61
00:04:41,990 --> 00:04:43,910
And this X is a global variable.

62
00:04:47,410 --> 00:04:50,170
So this is global mediæval.

63
00:04:55,350 --> 00:04:59,880
And this is my local variable.

64
00:05:01,320 --> 00:05:01,590
OK.

65
00:05:03,270 --> 00:05:08,750
Now, if you were to right, she yelled X.

66
00:05:10,320 --> 00:05:11,700
So what should be my output?

67
00:05:13,170 --> 00:05:13,650
Let's see.

68
00:05:17,920 --> 00:05:19,460
So I'm out for this coming out to.

69
00:05:20,360 --> 00:05:21,110
Then why?

70
00:05:21,200 --> 00:05:24,380
Because local variable value is getting printer.

71
00:05:25,370 --> 00:05:30,940
Now, if you want to access global variable, we're doing rate scope resolution operator.

72
00:05:31,880 --> 00:05:32,750
Now let's test.

73
00:05:35,960 --> 00:05:36,900
So now it is.

74
00:05:38,340 --> 00:05:41,240
Doing OK, so this is global variable.

75
00:05:43,720 --> 00:05:49,930
Now, what if I remove this X now that does not allow.

76
00:05:51,900 --> 00:05:54,940
So global variable is getting printed.

77
00:05:56,110 --> 00:05:56,360
OK.

78
00:05:56,700 --> 00:05:58,170
So what if I do?

79
00:06:00,110 --> 00:06:03,720
What if I remove this scope resolution operator?

80
00:06:04,190 --> 00:06:05,060
So what will happen?

81
00:06:06,500 --> 00:06:09,230
So there are two possible things that can happen.

82
00:06:09,980 --> 00:06:13,390
So first will be rendered.

83
00:06:13,880 --> 00:06:15,500
Second, the come by level.

84
00:06:15,920 --> 00:06:17,610
Show us error at this lane.

85
00:06:19,130 --> 00:06:20,450
So let's see what will happen.

86
00:06:24,580 --> 00:06:27,330
So Tony is getting printed.

87
00:06:29,910 --> 00:06:36,480
So I told you that if we want to access a global variable, we will write school resolution operator

88
00:06:36,600 --> 00:06:38,510
before the name of the very well.

89
00:06:39,330 --> 00:06:42,660
But here I have not written the school resolution operator.

90
00:06:43,050 --> 00:06:44,490
So why it is working.

91
00:06:45,680 --> 00:06:51,920
Because compilation starts from top and it will go towards boredom.

92
00:06:52,610 --> 00:07:00,980
So when my compiler will reach line number 10, it already know that there is a variable that is existing

93
00:07:01,070 --> 00:07:02,090
at line number four.

94
00:07:02,270 --> 00:07:04,220
So it will not show us at it.

95
00:07:05,140 --> 00:07:05,430
OK.

96
00:07:05,870 --> 00:07:12,230
So when compiler will reach nine number 10, it knows that there is a variable called X, which is present

97
00:07:12,290 --> 00:07:12,800
already.

98
00:07:13,100 --> 00:07:14,700
So it will not give us error.

99
00:07:16,460 --> 00:07:18,260
Hence my output will be full.

100
00:07:19,640 --> 00:07:20,950
So this is hours work.

101
00:07:21,350 --> 00:07:23,000
So compiler is smart enough.

102
00:07:24,170 --> 00:07:24,430
OK.

103
00:07:25,250 --> 00:07:28,970
Now when I was having 10 here.

104
00:07:29,270 --> 00:07:36,320
So to differentiate between this local variable and this a global variable, then I used the scope resolution

105
00:07:36,320 --> 00:07:38,200
operator propelled the compiler.

106
00:07:38,220 --> 00:07:42,230
Do not get confused between this and the guess I want.

107
00:07:42,920 --> 00:07:44,450
This means I want a global.

108
00:07:45,190 --> 00:07:46,730
Don't show me the value of local.

109
00:07:48,050 --> 00:07:48,320
OK.

110
00:07:50,440 --> 00:07:52,030
You can also change.

111
00:07:53,410 --> 00:07:55,900
You can also change the value of X, for example.

112
00:07:56,200 --> 00:07:59,050
Let there does make X equals 20.

113
00:07:59,590 --> 00:08:01,480
So now 20 will be my outward.

114
00:08:05,360 --> 00:08:10,090
OK, so today's getting printer and hair access a global variable.

115
00:08:12,140 --> 00:08:13,800
So next, we knew we were loo.

116
00:08:14,450 --> 00:08:20,240
When exercise to get a better understanding of global and local variables.

117
00:08:21,240 --> 00:08:23,360
OK, so that is it for this video.

118
00:08:23,750 --> 00:08:24,200
Thank you.
