1 00:00:01,870 --> 00:00:02,410 Hello. 2 00:00:02,410 --> 00:00:08,830 In this lecture you will learn about the cplusplus writing techniques and language features. 3 00:00:09,730 --> 00:00:16,760 So Cplusplus is a very flexible language when it comes to formatting and writing code. 4 00:00:16,780 --> 00:00:20,290 So it's also a strong type language. 5 00:00:20,290 --> 00:00:26,620 So meaning that there are rules, but clearing the types of variables which you can use to your advantage 6 00:00:26,620 --> 00:00:30,220 by making the compiler help you write better code. 7 00:00:30,250 --> 00:00:39,190 In this section we will cover how to format Cplusplus code and the rules on declaring and scoping variables. 8 00:00:39,670 --> 00:00:43,150 In this lecture we are going to start with the white spaces. 9 00:00:43,390 --> 00:00:46,070 How you can use white spaces in cplusplus. 10 00:00:46,090 --> 00:00:55,930 So here, other than string literals in white spaces, you have free usage of white spaces. 11 00:00:55,930 --> 00:01:07,670 So you can as long as as many as you can use as many as tabs, spaces, uh, spaces, spaces and new 12 00:01:07,670 --> 00:01:08,270 lines. 13 00:01:08,300 --> 00:01:08,960 New lines. 14 00:01:08,960 --> 00:01:09,830 As you can see here. 15 00:01:09,830 --> 00:01:15,110 You won't get you won't you will not get any error because of it. 16 00:01:15,140 --> 00:01:22,670 Here, as you can see, you can use as long as many as new lines, tabs and spaces you want here. 17 00:01:24,820 --> 00:01:25,490 As you can see. 18 00:01:25,490 --> 00:01:26,540 Let's compile it. 19 00:01:26,570 --> 00:01:30,710 As you can see, C plus plus compiler doesn't care about them. 20 00:01:30,710 --> 00:01:31,790 So. 21 00:01:34,390 --> 00:01:40,180 So about C plus plus statements are eliminated by semicolons here, as you can see here. 22 00:01:40,660 --> 00:01:42,310 So let's create an example code. 23 00:01:42,310 --> 00:01:44,650 So to explain it better. 24 00:01:44,650 --> 00:01:53,260 So for example, let's create an integer variable, assign it four and integer equals integer derived 25 00:01:53,260 --> 00:01:53,980 by two. 26 00:01:53,980 --> 00:01:56,080 So we will get two from it. 27 00:01:56,080 --> 00:01:59,910 And let's print F print f this. 28 00:02:00,130 --> 00:02:10,090 As you can see here, we get we got an error because in print F so we have to use the print we have 29 00:02:10,090 --> 00:02:17,170 to use in include library, you will learn about how to include library and what library is in later 30 00:02:17,170 --> 00:02:17,950 lectures. 31 00:02:18,520 --> 00:02:25,590 But it's not a hard thing to learn, but you will learn in next lectures include here. 32 00:02:25,810 --> 00:02:26,040 Um. 33 00:02:26,710 --> 00:02:29,440 STD dot h here. 34 00:02:29,470 --> 00:02:33,160 As you can see, we got rid of this error here. 35 00:02:33,160 --> 00:02:34,600 Return. 36 00:02:34,600 --> 00:02:36,460 Uh, let's return zero from it. 37 00:02:36,460 --> 00:02:37,180 Integer function. 38 00:02:37,450 --> 00:02:39,850 As you can see here, this function returns zero. 39 00:02:39,880 --> 00:02:40,840 You will learn. 40 00:02:41,530 --> 00:02:45,880 And then here, as you can see, we got the format. 41 00:02:46,510 --> 00:02:47,650 Um, then. 42 00:02:48,690 --> 00:02:50,610 And let's print something on it. 43 00:02:50,610 --> 00:02:59,670 So as you can see, if you if you delete this, include statement, this we will get an error here, 44 00:02:59,670 --> 00:03:01,140 as you can see here. 45 00:03:02,330 --> 00:03:02,840 And. 46 00:03:03,870 --> 00:03:04,380 Yeah. 47 00:03:04,620 --> 00:03:12,090 Let's include our statement here and delete this common line. 48 00:03:12,180 --> 00:03:14,220 Clear And yeah. 49 00:03:14,220 --> 00:03:16,470 So let's print these values on it. 50 00:03:16,470 --> 00:03:23,400 Actually, let's, let's use the C out we will use. 51 00:03:25,530 --> 00:03:29,340 We will we will use the printf later in this course. 52 00:03:29,340 --> 00:03:31,720 So as you can see, we got an error from it. 53 00:03:31,740 --> 00:03:33,180 Let me write this code. 54 00:03:33,720 --> 00:03:43,830 The result result is we will pass E as you can see, we will pass E and then end line here. 55 00:03:43,830 --> 00:03:44,910 End line. 56 00:03:45,950 --> 00:03:47,930 So as you can see, we've got an error. 57 00:03:48,500 --> 00:03:52,340 So if you include the stream. 58 00:03:53,660 --> 00:03:56,840 Yeah, you will get rid of that error. 59 00:03:57,290 --> 00:04:03,920 That's because the STD library needs input output stream here, so. 60 00:04:05,170 --> 00:04:10,990 And and as you can see, if we delete the printer function so we are not using print function anymore. 61 00:04:11,560 --> 00:04:13,780 We don't need this library. 62 00:04:13,780 --> 00:04:22,300 And as you can see here, see line ID, this blue, just the gray, gray color, this text for it. 63 00:04:22,600 --> 00:04:25,060 And then here. 64 00:04:26,390 --> 00:04:29,450 As you can see here, we have a new line here. 65 00:04:30,020 --> 00:04:30,260 Um. 66 00:04:31,530 --> 00:04:35,490 Every between our line and let's run and compile our program. 67 00:04:35,490 --> 00:04:37,870 And we got a result here. 68 00:04:37,890 --> 00:04:40,380 The result is two. 69 00:04:40,890 --> 00:04:43,260 So let's try one example here. 70 00:04:43,290 --> 00:04:45,120 Just delete these new lines. 71 00:04:46,770 --> 00:04:47,220 Yes. 72 00:04:47,460 --> 00:04:54,360 Just let these new lines and let's try if this works here or this. 73 00:04:55,550 --> 00:04:55,910 Here. 74 00:04:57,470 --> 00:05:01,450 We need these two semicolons and we do this too. 75 00:05:01,460 --> 00:05:08,990 So you can put spaces on new lines between variable names or functions or whatever you want here and 76 00:05:08,990 --> 00:05:12,110 you can use here. 77 00:05:12,110 --> 00:05:15,560 As you can see, we got the same result. 78 00:05:15,560 --> 00:05:18,590 So there are some cases white Spaces is needed. 79 00:05:18,590 --> 00:05:23,570 For example, when declaring a variable, you must have a white space between the type and the variable 80 00:05:23,570 --> 00:05:24,110 name. 81 00:05:24,680 --> 00:05:29,690 So but the convention is to be judicious as possible to make the code readable. 82 00:05:29,690 --> 00:05:37,070 And while it's perfectly correct language wise to put all the statements in one line like a JavaScript, 83 00:05:37,070 --> 00:05:42,020 but it makes the code almost completely unreadable. 84 00:05:42,020 --> 00:05:48,890 So of course it's less readable than the previous, uh, previous codes here, as you can see here, 85 00:05:48,920 --> 00:05:52,580 let me here, this is more readable, right? 86 00:05:52,580 --> 00:05:54,910 So actually, let's, um. 87 00:05:56,470 --> 00:06:06,650 Let's correct let's note this because I'm uploading this files to every lectures, and you can download 88 00:06:06,670 --> 00:06:09,310 and use these codes by letter. 89 00:06:09,310 --> 00:06:21,640 So for example, correct by language wise, but readable and readable and readable. 90 00:06:22,570 --> 00:06:25,900 And let's collect let's write another code here. 91 00:06:26,110 --> 00:06:32,620 For example, let's so as you can, as you know, we can create a two variables at the same name. 92 00:06:32,620 --> 00:06:35,530 So I'm going to change these names here. 93 00:06:37,580 --> 00:06:38,600 Uh, so. 94 00:06:39,640 --> 00:06:47,770 Of course you can print the as long as you want, but you just can't create the same name, same name, 95 00:06:47,770 --> 00:06:49,600 variable, same named variable. 96 00:06:49,600 --> 00:06:53,860 So as you can see here, this is here. 97 00:06:55,840 --> 00:06:56,470 Here. 98 00:06:57,430 --> 00:07:00,580 This is correct. 99 00:07:00,610 --> 00:07:01,450 Correct. 100 00:07:01,450 --> 00:07:04,870 By language wise. 101 00:07:06,470 --> 00:07:12,290 All right, let's just create a program will compile. 102 00:07:13,280 --> 00:07:17,840 Without problem but unreadable. 103 00:07:18,170 --> 00:07:21,140 So I will explain why we need this. 104 00:07:21,290 --> 00:07:25,490 Readable and unreadable codes here now. 105 00:07:25,490 --> 00:07:26,300 So. 106 00:07:27,670 --> 00:07:34,120 Being in mind that if the code write code you write is viable, it may use. 107 00:07:34,150 --> 00:07:41,860 It may in use for decades, which means you may have to come back to code years after you've written 108 00:07:41,860 --> 00:07:42,070 it. 109 00:07:42,070 --> 00:07:46,100 And it means that other people will support your code too. 110 00:07:46,120 --> 00:07:54,890 So making your code readable is not only a courtesy to other developers, but unreadable code is always 111 00:07:54,890 --> 00:07:59,170 a likely target for replacement here, as you can see here. 112 00:07:59,650 --> 00:08:03,190 Of course, it's more readable than this, so. 113 00:08:04,320 --> 00:08:05,250 In this lecture. 114 00:08:05,250 --> 00:08:10,320 In next lecture, you will learn about the formatting, the code in C plus plus. 115 00:08:10,320 --> 00:08:11,970 So see you in the next lecture.