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