1 00:00:01,960 --> 00:00:03,400 After the return trip. 2 00:00:04,310 --> 00:00:05,760 Uh, the parameters. 3 00:00:05,780 --> 00:00:07,100 The function name. 4 00:00:07,110 --> 00:00:08,790 And have been determined. 5 00:00:08,810 --> 00:00:12,500 You need to define the body of the parameter. 6 00:00:12,510 --> 00:00:18,060 So we're going to first, uh, make the return time, then our function name for some. 7 00:00:18,060 --> 00:00:25,130 My function, uh, the parameters for this function is going to go, for example, my integer. 8 00:00:25,130 --> 00:00:28,640 And this is the function. 9 00:00:29,970 --> 00:00:31,120 Uh, but here. 10 00:00:31,170 --> 00:00:39,570 So the code for a function must appear between a pair of braces here, as you can see here. 11 00:00:39,600 --> 00:00:46,590 So if the function returns the value, then the function must have at least one line. 12 00:00:46,620 --> 00:00:51,810 The last line in the function with the return statement here. 13 00:00:52,950 --> 00:01:00,390 So this must return the appropriate type or type that can be implicitly converted to the return type 14 00:01:00,390 --> 00:01:01,520 of the function. 15 00:01:01,530 --> 00:01:09,570 So as mentioned before, if the function is declared as auto here, the compiler will deduce the return 16 00:01:09,570 --> 00:01:09,870 type. 17 00:01:09,870 --> 00:01:14,880 So in this case, the return statement must return the same type. 18 00:01:15,610 --> 00:01:21,940 Now, when a function is called the compiler checks all the overloads of the function to find one that 19 00:01:21,940 --> 00:01:24,210 matches the parameter in the calling code. 20 00:01:24,220 --> 00:01:28,160 So if there is a no exact match, then the standard and those are defined. 21 00:01:28,180 --> 00:01:36,130 Type conversions are performed, so the values provided by the calling code may be different type from 22 00:01:36,130 --> 00:01:37,220 parentheses here. 23 00:01:37,240 --> 00:01:38,770 So parameters. 24 00:01:39,430 --> 00:01:45,730 So by default, parameters are passed by value and the copy is made. 25 00:01:45,730 --> 00:01:46,960 So which means that the. 26 00:01:47,960 --> 00:01:53,300 Parameters are treated as local variables in the function like that here. 27 00:01:53,300 --> 00:02:00,140 So you can't use the my integer variable outside the function here though these are the just local variables 28 00:02:00,140 --> 00:02:04,340 that you can use these variables inside the function. 29 00:02:04,340 --> 00:02:05,060 So. 30 00:02:07,180 --> 00:02:13,390 Uh, the variety of the function can decide to pass parameter by reference either through the pointer 31 00:02:13,390 --> 00:02:14,830 or a C++ reference. 32 00:02:14,840 --> 00:02:22,270 So pass by reference means that the variable in the calling code can be altered by the function, but 33 00:02:22,270 --> 00:02:27,220 this can control the by making the parameters constant here. 34 00:02:27,220 --> 00:02:33,790 So in which case, the reason for passing my reference is to prevent the potentially costly copying 35 00:02:33,820 --> 00:02:35,080 being made. 36 00:02:35,080 --> 00:02:41,950 So the built in arrays are always passed as a pointer to the first item to the array. 37 00:02:41,980 --> 00:02:47,310 Here, the compiler will create the temporaries when needed. 38 00:02:47,320 --> 00:02:53,440 So for example, when a parameter here for example, it's called void, F the F when a parameter is 39 00:02:53,440 --> 00:02:59,740 a const reference and the calling code pass the pass as a literal. 40 00:02:59,740 --> 00:03:04,930 A temporary object is created here and it's only available to the function here. 41 00:03:05,200 --> 00:03:13,750 Let's go to the function float and here we're going to make the F here. 42 00:03:15,890 --> 00:03:25,850 F 1.0, for example, or double double d d equals. 43 00:03:26,710 --> 00:03:27,730 2.0. 44 00:03:27,760 --> 00:03:29,980 As you know, this is the plot number. 45 00:03:29,980 --> 00:03:31,390 And here. 46 00:03:31,870 --> 00:03:33,970 And we're going to. 47 00:03:34,880 --> 00:03:45,500 Add the F pass the the variable, the double variable to the r f function here, which returns nothing. 48 00:03:45,500 --> 00:03:48,620 But we have a const parameter here. 49 00:03:49,350 --> 00:03:49,760 Be. 50 00:03:51,400 --> 00:03:58,030 So here this is OC OC and temporary float is created. 51 00:03:58,480 --> 00:04:01,180 And this is actually the almost the same. 52 00:04:01,810 --> 00:04:12,090 And it's OC and the temporary float is created here actually in this, not in this line. 53 00:04:12,100 --> 00:04:16,870 In this line we have a OC and it called can compile successfully. 54 00:04:17,080 --> 00:04:22,900 And in F when we pass 1.0 as parameter, the temporary float is created. 55 00:04:22,900 --> 00:04:31,570 And then when we're going to pass the D as a parameter, the temporary float is clearly created as well 56 00:04:31,570 --> 00:04:38,350 here and we can pass the initialize our list list in this function here so you can pass, initialize 57 00:04:38,350 --> 00:04:44,220 our list as a parameter if that list can be converted to the type of the parameter. 58 00:04:44,230 --> 00:04:48,250 So for example, let's we're going to create the another struct here. 59 00:04:48,310 --> 00:04:53,060 Actually, we can delete this course and we can create another structure. 60 00:04:53,110 --> 00:04:54,520 We can delete this as well. 61 00:04:56,240 --> 00:04:58,220 Struct point. 62 00:04:58,250 --> 00:05:07,910 Here this going take integer x here integer a or integer integer P here. 63 00:05:09,600 --> 00:05:10,110 Here. 64 00:05:10,260 --> 00:05:16,050 So we're going to make the under function name set point. 65 00:05:16,380 --> 00:05:19,630 And the point, as you can see, the point is a struct. 66 00:05:19,650 --> 00:05:23,460 We're going to take the point struct as a parameter. 67 00:05:24,700 --> 00:05:26,860 And name it Pete here. 68 00:05:26,890 --> 00:05:31,390 So in the main function, we're going to code a point. 69 00:05:31,390 --> 00:05:42,370 We're going to create a point object named P and reach the P dot A equals fun and P dot B equals one 70 00:05:42,370 --> 00:05:42,970 as well. 71 00:05:43,300 --> 00:05:45,820 And here we're going to set point. 72 00:05:45,820 --> 00:05:54,310 We're going to use the set point function and we're going to pass to pass P as a parameter and we're 73 00:05:54,310 --> 00:05:56,590 going to set point here. 74 00:05:57,700 --> 00:05:59,470 Uh, using the color braces. 75 00:05:59,950 --> 00:06:02,980 Your one and one here. 76 00:06:04,090 --> 00:06:09,980 And, uh, we're gonna return zero, as always, in the main function here. 77 00:06:10,000 --> 00:06:11,200 So. 78 00:06:12,910 --> 00:06:18,760 This code defines a structure that has two members here. 79 00:06:18,790 --> 00:06:21,110 Actually, let's make it look nice here like this. 80 00:06:21,130 --> 00:06:27,190 This structure has a two members, and in the main function, a new instance of point is created on 81 00:06:27,190 --> 00:06:32,430 the stack and it is initialized by accessing their members directly. 82 00:06:32,440 --> 00:06:38,170 So the instance is then passed to a function that has point parameters. 83 00:06:38,170 --> 00:06:42,490 And since the parameter of set point here, set point is passed by value. 84 00:06:42,520 --> 00:06:48,310 The compiler creates a copy of the structure on the stack of the function here. 85 00:06:48,310 --> 00:06:51,780 And the second call of the set point does the same. 86 00:06:51,790 --> 00:06:58,480 The compiler will create a temporary point object on the stack of the function and initialize it with 87 00:06:58,480 --> 00:07:01,330 the values in the initialized list.