1 00:00:01,860 --> 00:00:03,330 After the return type. 2 00:00:04,300 --> 00:00:08,710 Uh, the parameters, the function name and have been determined. 3 00:00:08,740 --> 00:00:12,430 You need to define the body of the parameters. 4 00:00:12,430 --> 00:00:15,680 So we're going to firstly make the return time. 5 00:00:15,700 --> 00:00:23,080 Then our function name, for example, my function, the parameters of this function is going to get, 6 00:00:23,080 --> 00:00:25,030 for example, my integer. 7 00:00:25,030 --> 00:00:28,660 And this is the function. 8 00:00:29,960 --> 00:00:31,070 Uh, body here. 9 00:00:31,070 --> 00:00:39,470 So the code for a function must appear between a pair of braces here, as you can see here. 10 00:00:39,470 --> 00:00:46,490 So if the function returns a value, then the function must have at least one line. 11 00:00:46,520 --> 00:00:51,800 The last line in the function with the return statement here. 12 00:00:52,790 --> 00:01:00,320 So this must return the appropriate type or type that can be implicitly converted to the return type 13 00:01:00,320 --> 00:01:01,430 of the function. 14 00:01:01,430 --> 00:01:09,500 So as mentioned before, if the function is declared as auto here, the compiler will deduce the return 15 00:01:09,500 --> 00:01:09,800 type. 16 00:01:09,800 --> 00:01:14,840 So in this case, the return statement must return the same type. 17 00:01:15,450 --> 00:01:21,630 Now, when a function is called, the compiler checks all the overloads of the function to find one 18 00:01:21,630 --> 00:01:24,150 that matches the parameter in the calling code. 19 00:01:24,150 --> 00:01:30,330 So if there is a no exact match, then the standard and user defined type conversions are performed. 20 00:01:30,330 --> 00:01:37,130 So the values provided by the calling code may be different type from parentheses here. 21 00:01:37,140 --> 00:01:38,760 So parameters. 22 00:01:39,210 --> 00:01:45,660 So by default parameters are passed by value and the copy is made. 23 00:01:45,660 --> 00:01:47,010 So which means that the. 24 00:01:47,920 --> 00:01:53,230 Parameters are treated as local variables in the function like that here. 25 00:01:53,230 --> 00:01:58,390 So you can't use the my integer variable outside the function here. 26 00:01:58,540 --> 00:02:04,240 These are the just local variables that you can use these variables inside the function. 27 00:02:04,240 --> 00:02:05,020 So. 28 00:02:07,200 --> 00:02:13,320 Uh, the variety of the function can decide to pass parameter by reference either through the pointer 29 00:02:13,320 --> 00:02:14,790 or a C plus plus reference. 30 00:02:14,790 --> 00:02:22,200 So pass by reference means that the variable in the calling code can be altered by the function, but 31 00:02:22,200 --> 00:02:27,150 this can controlled by making the parameters constant here. 32 00:02:27,150 --> 00:02:34,470 So in which case the reason for passing by reference is to prevent the potentially costly copying being 33 00:02:34,470 --> 00:02:35,040 made. 34 00:02:35,040 --> 00:02:41,880 So the built in arrays are always passed as a pointer to the first item to the array. 35 00:02:41,880 --> 00:02:47,250 Here, the compiler will create the temporaries when needed. 36 00:02:47,250 --> 00:02:51,750 So for example, when a parameter here, for example, let's create a void. 37 00:02:51,750 --> 00:02:59,760 If the when a parameter is a const reference and the calling code uh, passed pass as a literal, a 38 00:02:59,760 --> 00:03:04,890 temporary object is created here and it's only available to the function here. 39 00:03:05,100 --> 00:03:13,680 Let's create a function float and here we're going to make the F here. 40 00:03:15,850 --> 00:03:19,420 F 1.0, for example. 41 00:03:19,450 --> 00:03:20,740 Or double. 42 00:03:21,670 --> 00:03:22,510 Double d. 43 00:03:23,590 --> 00:03:25,780 D equals. 44 00:03:26,640 --> 00:03:27,620 2.0. 45 00:03:27,630 --> 00:03:29,880 As you know, this is the plot number. 46 00:03:29,880 --> 00:03:33,840 And here and we're going to. 47 00:03:34,750 --> 00:03:45,400 Add the F pass the D variable, the double variable to the our f function here which returns nothing. 48 00:03:45,400 --> 00:03:48,580 But we have a const parameter here. 49 00:03:49,330 --> 00:03:49,540 The. 50 00:03:51,240 --> 00:03:52,770 So here, this is. 51 00:03:52,770 --> 00:03:53,730 Okay. 52 00:03:53,820 --> 00:03:54,450 Okay. 53 00:03:54,450 --> 00:03:57,960 And temporary float is created. 54 00:03:58,260 --> 00:04:01,170 And this is actually the almost the same. 55 00:04:01,710 --> 00:04:03,600 And it's okay. 56 00:04:03,600 --> 00:04:10,950 And the temporary float is created here actually, in this. 57 00:04:10,950 --> 00:04:12,000 Not in this line. 58 00:04:12,000 --> 00:04:13,590 In this line we have, uh. 59 00:04:13,590 --> 00:04:14,280 Okay. 60 00:04:14,280 --> 00:04:22,440 And it code can compile successfully and in f when we pass 1.0 as parameter, the temporary float is 61 00:04:22,440 --> 00:04:22,830 created. 62 00:04:22,830 --> 00:04:31,950 And, um, when we're going to pass the D as a parameter, the temporary float is created as well here 63 00:04:31,950 --> 00:04:36,870 and we can pass the initializer list list in this functions here. 64 00:04:36,870 --> 00:04:39,960 So you can pass initializer list as a parameter. 65 00:04:39,960 --> 00:04:44,160 If that list can be converted to the type of the parameter. 66 00:04:44,160 --> 00:04:48,120 So for example, let's we're going to create another struct here. 67 00:04:48,150 --> 00:04:53,010 Actually, we can delete this codes, we can create another struct here. 68 00:04:53,010 --> 00:04:54,510 We can delete this as well. 69 00:04:55,930 --> 00:04:58,750 Uh, struct point here. 70 00:04:58,780 --> 00:05:02,080 This is going to take an integer x here. 71 00:05:02,200 --> 00:05:05,140 An integer A or integer. 72 00:05:06,280 --> 00:05:07,930 Integer B here. 73 00:05:09,470 --> 00:05:10,100 Here. 74 00:05:10,100 --> 00:05:15,980 So we're going to make the ender function named set point. 75 00:05:16,430 --> 00:05:19,550 And the point, as you can see, the point is a struct. 76 00:05:19,550 --> 00:05:23,480 We're going to take the point struct as a parameter. 77 00:05:24,510 --> 00:05:26,820 And name it here. 78 00:05:26,820 --> 00:05:31,280 So in the main function, we're going to code a point. 79 00:05:31,290 --> 00:05:42,330 We're going to create a point object named P and reach the P dot A equals one and P dot B equals one 80 00:05:42,330 --> 00:05:42,990 as well. 81 00:05:42,990 --> 00:05:45,720 And here we're going to set point. 82 00:05:45,750 --> 00:05:53,160 We're going to use the set point function and we're going to pass to pass P as a parameter. 83 00:05:53,640 --> 00:05:56,550 And we're going to set point here. 84 00:05:57,660 --> 00:06:00,220 Uh, using the curly braces here. 85 00:06:00,240 --> 00:06:02,970 One and one here. 86 00:06:03,960 --> 00:06:09,920 And we're going to return zero, as always in main function here. 87 00:06:09,930 --> 00:06:11,010 So. 88 00:06:12,600 --> 00:06:17,760 Uh, this code defines a structure that has two members. 89 00:06:17,910 --> 00:06:18,660 Here. 90 00:06:18,690 --> 00:06:20,520 Actually, let's make it look nice here. 91 00:06:20,520 --> 00:06:21,010 Like this. 92 00:06:21,030 --> 00:06:27,120 This structure has a two members, and in the main function, a new instance of point is created on 93 00:06:27,120 --> 00:06:32,400 the stack, and it is initialized by accessing their members directly. 94 00:06:32,400 --> 00:06:39,570 So the instance is then passed to a function that has point parameters as the parameter of set point 95 00:06:39,600 --> 00:06:40,080 here. 96 00:06:40,110 --> 00:06:42,390 Set point is passed by value. 97 00:06:42,420 --> 00:06:49,920 The compiler creates a copy of the structure on the stack of the function here, and the second call 98 00:06:49,920 --> 00:06:51,660 of the set point does the same. 99 00:06:51,660 --> 00:06:58,440 The compiler will create a temporary point object on the stack of the function and initialize it with 100 00:06:58,440 --> 00:07:01,320 the values in the initializer list.