1 00:00:00,440 --> 00:00:06,440 If a function calculates a value that can be calculated at the compile time, you can mark it on the 2 00:00:06,440 --> 00:00:13,280 left of the declaration with the, for example, const expression here. 3 00:00:13,700 --> 00:00:14,570 Like this. 4 00:00:15,720 --> 00:00:23,060 Here, with this the you're going to indicate that the compiler can optimize the code by computing the 5 00:00:23,060 --> 00:00:25,110 value at the compile time. 6 00:00:25,130 --> 00:00:29,480 So if the function value can be calculated at the compile time, it means that the parameters in the 7 00:00:29,480 --> 00:00:34,400 function function call must be value can be calculated at the compile time. 8 00:00:34,400 --> 00:00:42,170 So it means that the parameters uh, in a function must be known at compile time, and so they must 9 00:00:42,170 --> 00:00:43,040 be literal. 10 00:00:43,040 --> 00:00:45,260 So the function must also be a single line. 11 00:00:45,260 --> 00:00:53,990 So if there is if these restrictions are not met, then the compiler is free to ignore the specified. 12 00:00:54,030 --> 00:01:00,200 But if you just compile it, the compiler won't say nothing here, but probably it will ignore the if 13 00:01:00,200 --> 00:01:03,820 these restrictions are not met. 14 00:01:04,490 --> 00:01:13,160 So the related in this in line specify that this can be placed on the left of a function here. 15 00:01:13,970 --> 00:01:14,720 In line. 16 00:01:15,920 --> 00:01:22,310 This kind of the left of a function, the function declaration as a suggestions to the compiler that 17 00:01:22,310 --> 00:01:29,540 when other code call calls this function rather than rather than the compiler inserting a jump to the 18 00:01:29,540 --> 00:01:36,330 function in memory, the compiler should put a copy of the actual code in the calling function. 19 00:01:36,350 --> 00:01:43,880 Again, the compiler is free to ignore specifiers if this restrictions is not met. 20 00:01:44,870 --> 00:01:45,350 Here. 21 00:01:45,620 --> 00:01:48,910 So we're going to determine the return type here. 22 00:01:48,920 --> 00:01:54,780 So the functions may be written to run a routine and not a return value. 23 00:01:54,800 --> 00:02:03,680 So if this case this is the case, you must specify that the function returns the void here, void here. 24 00:02:03,680 --> 00:02:08,450 But in this case, you're going to see error because we are returning something, right? 25 00:02:08,450 --> 00:02:11,210 So in most cases, a function will return a value. 26 00:02:11,240 --> 00:02:18,560 So if we only indicate that the function has completed correctly so there's no requirement that the 27 00:02:18,740 --> 00:02:22,340 column function obtains the return value or does anything with it. 28 00:02:22,340 --> 00:02:27,670 So the calling function can simply ignore the return value. 29 00:02:27,680 --> 00:02:32,390 So there are two types two ways to specify the return type. 30 00:02:32,840 --> 00:02:37,550 The first way is to give the type before the function name like this. 31 00:02:38,240 --> 00:02:41,060 In this case, this is an integer that returns integer. 32 00:02:41,420 --> 00:02:46,280 And this is the method used in most examples in this course so far. 33 00:02:46,310 --> 00:02:55,130 The second way is calling the trailing return type and requires that you place auto here auto as a return 34 00:02:55,130 --> 00:03:04,370 type before the function function name as and use the this syntax here like this. 35 00:03:06,100 --> 00:03:06,850 Integer. 36 00:03:07,070 --> 00:03:14,200 We use the syntax to give the actual return type after the parameter list. 37 00:03:14,290 --> 00:03:15,130 So. 38 00:03:16,250 --> 00:03:20,510 This function is so simple that is good candidate to be inline. 39 00:03:20,510 --> 00:03:27,200 So the return type on the left is given out here, meaning that the actual return type is specified 40 00:03:27,200 --> 00:03:35,900 after the parameter list and this operator and int means that the return type is an integer. 41 00:03:36,060 --> 00:03:40,780 And this syntax has the same effect as using the integer on the left. 42 00:03:40,790 --> 00:03:47,390 So but this is like this is useful when a function is templated and the return type may not be noticeable 43 00:03:47,390 --> 00:03:47,770 here. 44 00:03:47,780 --> 00:03:55,850 So in this trivial example you can omit return type entirely and just use the auto on the left of the 45 00:03:55,850 --> 00:03:56,630 function name. 46 00:03:56,630 --> 00:04:02,980 So this syntax means that the compiler will deduce the return type from the actual value returned. 47 00:04:02,990 --> 00:04:10,280 So clearly the compiler will note will only know what return type is from the function body, so you 48 00:04:10,280 --> 00:04:14,410 can not provide a prototype for such functions. 49 00:04:14,420 --> 00:04:20,810 So finally, if a function does not return at all, for example, if it calls into a never ending loop 50 00:04:20,810 --> 00:04:23,510 to pull some value. 51 00:04:23,900 --> 00:04:35,840 So if it does not return value at all, you can mark it with the C++ 11 attribute, the no return no 52 00:04:35,840 --> 00:04:38,690 return attribute with this here. 53 00:04:38,690 --> 00:04:46,400 So the compiler can use this attribute to read write a more efficient code because it knows that it 54 00:04:46,400 --> 00:04:50,300 does not need to provide the return value here.