1
00:00:00,450 --> 00:00:05,670
In this lecture you will learn about the default values in C plus plus.

2
00:00:05,670 --> 00:00:10,500
So variables of a built in types should be initialized before you first use them.

3
00:00:10,500 --> 00:00:17,660
But there are some situations when the compiler will provide a default value.

4
00:00:17,670 --> 00:00:21,240
So if you declare a variable at a file scope.

5
00:00:22,090 --> 00:00:28,960
Uh, or globally in your project and you don't give it an initial value, the compiler will give it

6
00:00:28,960 --> 00:00:30,730
a default value, for example.

7
00:00:30,730 --> 00:00:35,050
So let's outside create an outside variable.

8
00:00:35,260 --> 00:00:42,400
Integer outside and then create an inside variable, for example.

9
00:00:42,400 --> 00:00:51,580
Or let's increment outside by one and then print f our outside.

10
00:00:52,210 --> 00:00:54,700
This is the integer manager integer.

11
00:00:54,700 --> 00:01:02,830
So we will we're going to use the decimal format specifier here and then pass our outside as an argument

12
00:01:02,920 --> 00:01:06,460
and let's compile our application and see what happens.

13
00:01:06,460 --> 00:01:09,400
As you can see here, we got the one.

14
00:01:09,400 --> 00:01:10,240
So.

15
00:01:11,290 --> 00:01:21,370
The code will compile and run and it printed the value one so the compiler has initialized the outside

16
00:01:21,910 --> 00:01:22,910
to zero.

17
00:01:22,930 --> 00:01:27,000
So when it's incremented to one.

18
00:01:27,010 --> 00:01:41,350
So actually, let me write this here outside um, zero by default and here incremented increment by

19
00:01:41,350 --> 00:01:42,160
one.

20
00:01:42,850 --> 00:01:44,500
Uh, by plus one.

21
00:01:45,740 --> 00:01:46,460
Plus one.

22
00:01:46,460 --> 00:01:52,860
And here, um, output here, one here.

23
00:01:53,150 --> 00:01:59,090
And let's create another example here, which called inside.

24
00:02:00,090 --> 00:02:04,970
So create an inside, inside actually integer inside.

25
00:02:04,980 --> 00:02:09,030
It's going to be an integer type inside and do not assign anything on it.

26
00:02:09,030 --> 00:02:17,430
And let's increment inside by one plus plus here and let's print the inside variable.

27
00:02:17,430 --> 00:02:28,890
Actually, let's mention here inside of this is an outside one outside and then print the inside one

28
00:02:28,890 --> 00:02:29,340
here.

29
00:02:29,340 --> 00:02:31,920
Print f, okay.

30
00:02:32,730 --> 00:02:34,140
Inside.

31
00:02:36,190 --> 00:02:36,610
Yes.

32
00:02:37,650 --> 00:02:41,640
And here pass insight as an argument here.

33
00:02:41,820 --> 00:02:43,890
Parameter here and then.

34
00:02:45,390 --> 00:02:49,890
Let's compile and run our application.

35
00:02:50,670 --> 00:02:51,870
So as you can.

36
00:02:52,350 --> 00:02:52,860
I'm sorry.

37
00:02:52,860 --> 00:02:55,020
I have to add the new line here.

38
00:02:55,260 --> 00:02:58,490
We don't have to add to the last line, but it's okay.

39
00:02:58,500 --> 00:03:00,370
So let's add it just in case.

40
00:03:00,390 --> 00:03:03,450
As you can see, inside, one outside one.

41
00:03:03,450 --> 00:03:04,350
So.

42
00:03:05,990 --> 00:03:16,790
And here the compiler will compile and the increment operator is being used as a uninitialized variable.

43
00:03:16,790 --> 00:03:27,590
So in the last lecture we have another example of the compiler providing the default value static.

44
00:03:27,590 --> 00:03:31,640
So here, let's create an example here.

45
00:03:32,690 --> 00:03:38,480
Um, static integer count here, for example, return.

46
00:03:38,900 --> 00:03:41,230
Uh, here we're just going to be here.

47
00:03:41,240 --> 00:03:45,470
Return plus plus, count here count.

48
00:03:45,980 --> 00:03:52,880
So as you can see here, actually it's let's instead of writing like this, let's create another count

49
00:03:52,880 --> 00:04:00,890
function so we don't mess with the main function here and call our count function whenever we want.

50
00:04:01,100 --> 00:04:06,970
And then let's add here our integer count function.

51
00:04:07,910 --> 00:04:10,640
Uh, then static.

52
00:04:10,880 --> 00:04:14,840
Let's add the static integer count variable here.

53
00:04:14,840 --> 00:04:20,000
And this counter, as you can see here, this function returns an integer.

54
00:04:20,000 --> 00:04:21,890
So we're going to return the integer.

55
00:04:21,890 --> 00:04:25,190
As you can see, count is integer, count variable is integer.

56
00:04:25,190 --> 00:04:28,180
So it's in order to more understandable.

57
00:04:28,180 --> 00:04:32,090
So let's like write like variable type.

58
00:04:32,090 --> 00:04:34,490
So here, plus plus count.

59
00:04:36,090 --> 00:04:36,810
You will see.

60
00:04:37,230 --> 00:04:38,250
Actually, my count.

61
00:04:38,250 --> 00:04:38,490
Plus.

62
00:04:38,490 --> 00:04:39,420
Plus my count.

63
00:04:39,810 --> 00:04:40,680
My count.

64
00:04:40,800 --> 00:04:44,100
So this is a simple function that maintains a count.

65
00:04:44,100 --> 00:04:53,070
So the variable count here, my count is marked with the static search class modifier, meaning that

66
00:04:53,070 --> 00:04:57,900
the variable has the same lifetime as the application so located when?

67
00:04:57,900 --> 00:05:04,970
So this allocated when the code starts and they are located when the program ends.

68
00:05:04,980 --> 00:05:08,550
So however it has an internal linkage.

69
00:05:08,550 --> 00:05:14,070
So meaning the variable can only be used within the scope of where it is declared.

70
00:05:14,070 --> 00:05:16,110
So the counter function.

71
00:05:16,260 --> 00:05:26,130
So the compiler will initialize the count my count variable with a default value of zero.

72
00:05:26,850 --> 00:05:35,040
And then so that the first time counter function is called, it will return the value zero.

73
00:05:35,190 --> 00:05:37,420
So, so, so.

74
00:05:37,420 --> 00:05:39,820
But it will return the value one.

75
00:05:39,820 --> 00:05:41,110
I'm sorry, I'm mistaken.

76
00:05:41,110 --> 00:05:43,970
It will return the value one because we increment it.

77
00:05:43,970 --> 00:05:51,310
This my count by one returns one returns one here.

78
00:05:52,270 --> 00:05:53,440
Okay.

79
00:05:54,400 --> 00:05:58,870
Actually, let's print death count.

80
00:06:00,030 --> 00:06:00,840
Function.

81
00:06:02,560 --> 00:06:03,160
From.

82
00:06:04,300 --> 00:06:14,740
Shown here and the, uh, counter here, uh, past counter and let's see what happens.

83
00:06:14,740 --> 00:06:22,990
As you can see here, count function gave counter function gave us, returned us one.

84
00:06:24,790 --> 00:06:30,160
And we have a new initializer list, syntax of C plus plus 11.

85
00:06:31,330 --> 00:06:35,050
So this is the update upgrade on C plus plus language here.

86
00:06:35,050 --> 00:06:42,730
So the initial initializer list, syntax of C plus plus 11 provides a way for you.

87
00:06:42,760 --> 00:06:50,140
Declare a variable and specify that you want it initialized by the compiler to the default value for

88
00:06:50,140 --> 00:06:50,970
the type.

89
00:06:50,980 --> 00:06:59,050
So for example, let's create an example variable here, integer A here and then like this.

90
00:06:59,050 --> 00:07:02,530
So it might be strange, but I will explain all of this.

91
00:07:02,530 --> 00:07:11,560
So of course when you read this code, it's you have to know that the default value for an integer is

92
00:07:11,560 --> 00:07:12,220
zero.

93
00:07:13,230 --> 00:07:21,150
So again, it's much easier, easier and more explicit to simply initialize the variable to a value.

94
00:07:21,180 --> 00:07:23,730
E equals equals zero.

95
00:07:23,730 --> 00:07:30,780
Here, of course it's more easy, but the rules for the default values are simple.

96
00:07:30,810 --> 00:07:33,330
A value of zero.

97
00:07:33,750 --> 00:07:39,700
So integers and floating point numbers have a default value of zero for a character.

98
00:07:39,720 --> 00:07:42,120
The default value is.

99
00:07:42,450 --> 00:07:44,910
Let me show here like this.

100
00:07:44,910 --> 00:07:45,960
This is the zero.

101
00:07:46,170 --> 00:07:54,660
So for a bool is false and for a pointer is the constant nullptr here.

102
00:07:55,200 --> 00:07:57,750
So this is the also zero.

103
00:07:57,780 --> 00:08:02,400
I want to here mention here and here.

104
00:08:05,820 --> 00:08:13,060
Char default value is our default value is here.

105
00:08:13,060 --> 00:08:30,370
Parentheses slash zero boolean bool default value is false and the floating point number is same as

106
00:08:30,370 --> 00:08:33,280
the integer.

107
00:08:33,370 --> 00:08:35,020
It is zero.

108
00:08:35,230 --> 00:08:38,380
And let me mention it for pointer.

109
00:08:38,380 --> 00:08:40,440
It's a pointer.

110
00:08:41,110 --> 00:08:53,740
Pointer is default, value is nullptr, which I will explain what nullptr is.

111
00:08:53,740 --> 00:09:01,360
So in next lecture we're going to learn the declarations with without a type.

112
00:09:01,360 --> 00:09:03,940
So I'm waiting you in next lecture.
