1 00:00:01,150 --> 00:00:09,070 C plus plus 11 introduced a mechanism for declaring that a variable's type should be determined from 2 00:00:09,070 --> 00:00:14,980 the data it is initialized with, and that is the auto keyword here. 3 00:00:15,310 --> 00:00:23,650 So this is a minor confusion here because the prior C plus plus 11 prior to C plus plus 11, the auto 4 00:00:23,650 --> 00:00:27,010 key was used to declare the automatic variables. 5 00:00:27,040 --> 00:00:32,110 That is the variables that are automatically allocated on the stack in a function. 6 00:00:32,110 --> 00:00:40,240 So other than variables declared at a file scope or a static, are the other variables in this course 7 00:00:40,240 --> 00:00:46,870 so far have been automatic variables, and automatic variables are the most widely used storage class. 8 00:00:47,470 --> 00:00:56,590 So since it was optional and applicable to most variables, the auto keyword was rarely used in C plus 9 00:00:56,590 --> 00:00:57,210 plus. 10 00:00:57,220 --> 00:01:00,710 So the C plus plus 11 took advantage of this. 11 00:01:00,710 --> 00:01:07,820 Remove the old meaning and gave the author the whole new meaning here. 12 00:01:07,820 --> 00:01:15,890 So if you're compiling all C plus plus code with the C plus plus 11 compiler and that old code uses 13 00:01:15,920 --> 00:01:24,140 auto, so you will get errors because the new compiler will assume auto will be used with the variables 14 00:01:24,140 --> 00:01:27,230 with no specified type. 15 00:01:27,230 --> 00:01:28,280 So. 16 00:01:29,200 --> 00:01:34,170 If this happens, simply search and delete each instance of auto. 17 00:01:34,180 --> 00:01:38,530 So it was redundant in C plus plus prior to C plus plus 11. 18 00:01:38,530 --> 00:01:43,210 And there was a little reason for developers to use it here. 19 00:01:43,240 --> 00:01:50,710 The auto keyword means that the compiler should create a variable with the type of the data that is 20 00:01:50,710 --> 00:01:51,670 assigned to it. 21 00:01:51,670 --> 00:01:55,230 So the variable can only have a single type. 22 00:01:55,240 --> 00:02:00,190 The type the compiler decides is a type it needs for the data assigned to it. 23 00:02:00,370 --> 00:02:06,670 So and you cannot use the variables elsewhere to hold data of a different type because the compiler 24 00:02:06,670 --> 00:02:10,270 needs to determine the type from an initializer. 25 00:02:10,270 --> 00:02:16,300 And it means that all auto variables must be initialized. 26 00:02:17,200 --> 00:02:17,920 Now. 27 00:02:18,190 --> 00:02:21,150 Now, I want to do some examples here. 28 00:02:21,160 --> 00:02:27,880 So let's create an auto variables, which I will explain all of these auto variables later and add comments 29 00:02:27,880 --> 00:02:28,720 to it. 30 00:02:29,380 --> 00:02:34,480 For example, 42 auto be 42. 31 00:02:36,260 --> 00:02:36,830 Here. 32 00:02:36,860 --> 00:02:44,060 Auto c 42 lx here auto d here. 33 00:02:44,840 --> 00:02:50,150 Um 1.11.0 f auto. 34 00:02:51,120 --> 00:02:51,960 E here. 35 00:02:53,490 --> 00:02:55,590 1.0. 36 00:02:57,000 --> 00:02:57,900 Auto. 37 00:02:59,690 --> 00:03:00,740 If here. 38 00:03:02,510 --> 00:03:04,850 Uh, if it's going to be character. 39 00:03:10,760 --> 00:03:11,180 Here. 40 00:03:14,960 --> 00:03:15,950 And auto. 41 00:03:18,590 --> 00:03:19,130 Here. 42 00:03:19,160 --> 00:03:19,640 True. 43 00:03:22,160 --> 00:03:22,940 Here. 44 00:03:23,510 --> 00:03:28,630 Now I want to add, um, variables after it. 45 00:03:28,640 --> 00:03:40,280 So this is the integer we created integer type because we assigned to just an integer and here we created 46 00:03:40,280 --> 00:03:43,790 the long type, just the long integer. 47 00:03:44,390 --> 00:03:47,780 So we created long, long integer. 48 00:03:48,880 --> 00:03:49,420 Here. 49 00:03:49,420 --> 00:03:51,510 We created the float. 50 00:03:52,370 --> 00:03:53,630 Here. 51 00:03:54,620 --> 00:04:03,890 Double note that there is no syntax to specify that an integer value is a single byte or two byte, 52 00:04:03,890 --> 00:04:11,240 so you cannot create an unsigned character variables or short variables this way. 53 00:04:11,880 --> 00:04:15,010 Uh, and here we created the character. 54 00:04:15,020 --> 00:04:17,300 Just a usual normal standard character. 55 00:04:18,410 --> 00:04:21,410 And here we created the bull here. 56 00:04:22,560 --> 00:04:27,630 So this is a tribal use of the auto keyword. 57 00:04:27,630 --> 00:04:36,690 You should some sometimes you create this auto keyword with this and the compiler will assign the type 58 00:04:36,690 --> 00:04:39,330 of this variable automatically. 59 00:04:39,330 --> 00:04:44,250 So now I want to create another example to show you how this happens. 60 00:04:44,250 --> 00:04:48,870 And here this things might might get confusing. 61 00:04:48,870 --> 00:04:56,940 So don't worry if you don't know about the tuple or vectors here, which you will learn in later lectures. 62 00:04:56,940 --> 00:05:04,770 So now I want to create a vector that will take two, uh, one tuple, uh, in the tuple we're going 63 00:05:04,770 --> 00:05:06,840 to have string and integer. 64 00:05:08,110 --> 00:05:10,180 Here, we're going to create the vector. 65 00:05:10,360 --> 00:05:13,180 As you can see here, vector is not a built in type. 66 00:05:13,180 --> 00:05:18,910 So we have to import from the import class of vector to use it. 67 00:05:18,910 --> 00:05:23,380 And as you can see here, the compiler created a include vector here. 68 00:05:24,460 --> 00:05:26,830 The vector here tuple. 69 00:05:28,350 --> 00:05:30,720 String integer here. 70 00:05:30,750 --> 00:05:37,800 So as you can see, we have a tuple and we need to import the string here. 71 00:05:39,820 --> 00:05:43,210 And here we're going to name it my cars. 72 00:05:44,180 --> 00:05:50,510 Uh, as you can see, we got an error because we didn't actually included the tuple here. 73 00:05:50,510 --> 00:05:54,620 So that's why we're going to include include. 74 00:05:55,320 --> 00:06:01,290 Couple here, as you can see here, our error gone away and then. 75 00:06:02,700 --> 00:06:03,300 Here. 76 00:06:03,660 --> 00:06:08,730 We're going to add variables to my car's vector. 77 00:06:08,760 --> 00:06:10,260 Here, my cars. 78 00:06:10,260 --> 00:06:11,800 I will explain all of these codes here. 79 00:06:11,820 --> 00:06:12,750 Don't worry. 80 00:06:13,350 --> 00:06:19,860 My car's pushback back make topple and we're going to pass the. 81 00:06:21,930 --> 00:06:26,960 For example, let's name some car BMW and its year here. 82 00:06:27,270 --> 00:06:32,280 As you can see, the first is string and the second parameter is integer. 83 00:06:32,280 --> 00:06:38,250 So let's input our the date of production. 84 00:06:38,580 --> 00:06:44,120 The year of production of our car, for example, 2001. 85 00:06:44,130 --> 00:06:45,420 My cars. 86 00:06:45,450 --> 00:06:47,820 Or let's make a model of it. 87 00:06:47,820 --> 00:06:49,500 So make it look nicer. 88 00:06:52,110 --> 00:06:55,080 5/5 series here. 89 00:06:55,110 --> 00:06:58,070 My cars push back. 90 00:06:58,770 --> 00:07:00,120 Make Topple. 91 00:07:00,810 --> 00:07:02,010 The fourth. 92 00:07:03,450 --> 00:07:04,290 Uh. 93 00:07:05,690 --> 00:07:06,380 Mustang. 94 00:07:06,770 --> 00:07:07,820 Mustang. 95 00:07:07,910 --> 00:07:08,750 Here. 96 00:07:10,040 --> 00:07:11,510 1989. 97 00:07:12,320 --> 00:07:13,580 My cars. 98 00:07:14,560 --> 00:07:16,330 The pushback. 99 00:07:17,680 --> 00:07:18,970 Make a couple. 100 00:07:20,960 --> 00:07:23,150 Uh, Volkswagen Golf here. 101 00:07:23,150 --> 00:07:25,370 2010. 102 00:07:26,680 --> 00:07:27,580 My car. 103 00:07:27,580 --> 00:07:28,150 Start. 104 00:07:28,150 --> 00:07:29,170 Push back. 105 00:07:29,870 --> 00:07:30,690 Make. 106 00:07:30,710 --> 00:07:31,340 Make. 107 00:07:31,380 --> 00:07:32,180 Topple. 108 00:07:33,400 --> 00:07:34,060 Uh, here. 109 00:07:34,060 --> 00:07:37,990 We're going to input the Land Rover. 110 00:07:38,500 --> 00:07:40,270 Land Rover. 111 00:07:41,380 --> 00:07:44,440 Land Rover here. 112 00:07:46,190 --> 00:07:49,610 2015 here. 113 00:07:50,030 --> 00:07:59,720 Now we're going to create a for loop here for here, Tupple string integer here. 114 00:07:59,990 --> 00:08:03,320 It's going to be like my vehicles. 115 00:08:06,000 --> 00:08:08,040 Here and then. 116 00:08:09,360 --> 00:08:10,470 My cars. 117 00:08:10,470 --> 00:08:11,700 We will iterate. 118 00:08:11,730 --> 00:08:17,550 My cars one by one here, and then we're going to print it out here. 119 00:08:17,580 --> 00:08:18,570 C out. 120 00:08:19,410 --> 00:08:20,130 C out. 121 00:08:20,130 --> 00:08:26,010 As you can see, we cannot use C out because we have to use a include STD. 122 00:08:27,930 --> 00:08:28,350 Here. 123 00:08:30,040 --> 00:08:32,250 Input output stream and see. 124 00:08:33,910 --> 00:08:35,950 Get here. 125 00:08:41,490 --> 00:08:42,150 Get. 126 00:08:42,940 --> 00:08:44,440 My vehicles. 127 00:08:45,870 --> 00:08:46,230 Here. 128 00:08:49,440 --> 00:08:50,100 Get. 129 00:08:50,930 --> 00:08:51,700 One. 130 00:08:51,710 --> 00:08:53,260 I will explain all of these codes. 131 00:08:53,270 --> 00:08:53,780 Don't worry. 132 00:08:53,780 --> 00:08:54,380 Here. 133 00:08:55,670 --> 00:08:58,040 And get one. 134 00:08:58,430 --> 00:09:00,530 My vehicles. 135 00:09:02,590 --> 00:09:04,060 And end line. 136 00:09:05,600 --> 00:09:07,700 And let's run our code here. 137 00:09:11,510 --> 00:09:12,020 Okay. 138 00:09:14,900 --> 00:09:17,840 Make it look nice and print it out again. 139 00:09:18,770 --> 00:09:25,100 So this code, as you can see, this is our okay, make it run it again. 140 00:09:25,100 --> 00:09:36,830 So here, as you can see here, this code uses the vector container here to as you know, we haven't 141 00:09:36,830 --> 00:09:39,920 used vector or tuples, so don't worry about them. 142 00:09:40,430 --> 00:09:46,280 You will learn in next lectures about vectors and tuples and other technologies in C plus plus here. 143 00:09:46,280 --> 00:09:51,020 But just keep in mind that you will learn it and don't panic here. 144 00:09:51,440 --> 00:09:58,490 So, uh, here the vector stores two value items using this tuple. 145 00:09:59,670 --> 00:10:01,800 So the tuple class is simple. 146 00:10:01,830 --> 00:10:08,460 You declare a list of the types of items in the tuple object and the declaration between the angled 147 00:10:08,700 --> 00:10:09,870 braces here. 148 00:10:09,870 --> 00:10:18,060 So the tuple string integer declaration says that the object will hold a string and an integer. 149 00:10:18,060 --> 00:10:24,780 So in that order, the make tuple function here make tuple function here. 150 00:10:25,720 --> 00:10:34,540 Is provided by the C plus plus standard library and will create a tuple object containing two values. 151 00:10:34,540 --> 00:10:40,150 The first is a string and the second is integer. 152 00:10:40,330 --> 00:10:45,760 So the pushback function will put the item into the vector container. 153 00:10:45,760 --> 00:10:53,080 So after the for cost of the pushback function, the here the vehicles. 154 00:10:54,340 --> 00:11:03,070 The vehicle's variable will contain actually the my car's variable will contain four items and each 155 00:11:03,100 --> 00:11:11,590 in the four items we're going to have two variables and each one is tuple with the name and birth year. 156 00:11:11,770 --> 00:11:20,710 And here, as you can see, the range for loops throughout the container and on each loop assigns the 157 00:11:21,040 --> 00:11:27,580 my vehicle variable with the next item in the container of my cars. 158 00:11:27,580 --> 00:11:34,600 So the values in the tuple are printed to the console, as you can see here in this function. 159 00:11:35,770 --> 00:11:37,170 And for loop here. 160 00:11:37,170 --> 00:11:43,830 So an item in the tuple here is accessed using the get. 161 00:11:45,320 --> 00:11:48,920 Parameterized function from the tuple. 162 00:11:48,950 --> 00:11:52,010 Here, as you can see here, this is a get function. 163 00:11:52,280 --> 00:11:55,160 This get function belongs to tuple here. 164 00:11:55,820 --> 00:11:56,960 So. 165 00:11:59,430 --> 00:12:08,130 And here, as you can see here, the first we assigned zero to get the first object of this tuple and 166 00:12:08,130 --> 00:12:17,370 then a space here and then get one, uh, gets the year of item in the tuple. 167 00:12:17,370 --> 00:12:22,800 And the result of this code is this output here. 168 00:12:23,010 --> 00:12:30,690 So the next text has poor formatting because it does not take into account the length of the names. 169 00:12:30,690 --> 00:12:35,730 So this can be addresses using the manipulators in next lectures. 170 00:12:35,730 --> 00:12:38,490 So we're going to create here. 171 00:12:39,930 --> 00:12:44,190 Uh, take a look at the for loop here. 172 00:12:46,040 --> 00:12:48,560 So the type of the. 173 00:12:49,350 --> 00:12:54,450 My vehicles is tuple, string and integer. 174 00:12:54,450 --> 00:13:02,340 So this is fairly simple type and as you use the standard template more, you could end up with some 175 00:13:02,340 --> 00:13:06,600 complicated type, particularly when you use iterators. 176 00:13:06,600 --> 00:13:10,690 So this is where our tool becomes useful. 177 00:13:10,820 --> 00:13:13,560 The here we're going to create a code. 178 00:13:15,020 --> 00:13:17,580 Okay, so let's comment it out. 179 00:13:19,160 --> 00:13:19,640 Here. 180 00:13:22,740 --> 00:13:23,010 Oops. 181 00:13:25,110 --> 00:13:25,380 Here. 182 00:13:28,640 --> 00:13:29,510 Commented out. 183 00:13:31,020 --> 00:13:32,250 And here. 184 00:13:36,700 --> 00:13:37,420 For. 185 00:13:38,800 --> 00:13:41,140 Autonomy vehicles. 186 00:13:43,490 --> 00:13:48,920 Girls and my cars and see out. 187 00:13:51,260 --> 00:13:53,420 Get zero. 188 00:13:54,970 --> 00:13:58,120 From the my vehicles. 189 00:13:59,360 --> 00:14:01,670 Vehicles and. 190 00:14:04,010 --> 00:14:04,460 Here. 191 00:14:06,000 --> 00:14:12,480 Get one from the my vehicles here and end line. 192 00:14:14,490 --> 00:14:17,760 So here. 193 00:14:20,580 --> 00:14:23,340 This is where R2 becomes useful here. 194 00:14:23,340 --> 00:14:28,090 So this code is the same but easier to read. 195 00:14:28,110 --> 00:14:32,670 So the my vehicles variable is still typed. 196 00:14:33,270 --> 00:14:44,340 It has a tuple string integer, but auto means you do not have to explicitly code this in like this 197 00:14:44,340 --> 00:14:45,330 example here. 198 00:14:45,330 --> 00:14:50,220 So this is more readable code and more useful on this case here.