1 00:00:00,910 --> 00:00:05,530 In this lecture you will learn about the constant expressions in C++. 2 00:00:05,530 --> 00:00:15,640 So C++ 11 introduce a key word called const X for your const expression, const expression, const expert 3 00:00:15,670 --> 00:00:16,150 here. 4 00:00:16,150 --> 00:00:22,660 So this is applied to an expression, and in the case that the expression should be evaluated at a compile 5 00:00:22,660 --> 00:00:24,580 time rather than at runtime. 6 00:00:24,580 --> 00:00:38,590 So for example, let's create an override code here, the const expression double P 1415 and let's create 7 00:00:38,740 --> 00:00:44,830 another const expression, double expression expr double. 8 00:00:45,070 --> 00:00:48,730 And here we're going to write to py. 9 00:00:49,660 --> 00:00:50,290 European. 10 00:00:51,620 --> 00:00:55,970 As you can see, our variable names cannot start with a number here. 11 00:00:55,970 --> 00:01:05,780 So that's why I brought alphabetical to here and two to multiply by pi here. 12 00:01:05,930 --> 00:01:12,050 So this is similar initialization constant declared with the cost keyboard. 13 00:01:12,080 --> 00:01:20,330 However, the cost expert here expression keyboard can also be applied to functions that return a value 14 00:01:20,330 --> 00:01:23,180 that can be evaluated at the compile time. 15 00:01:23,360 --> 00:01:28,410 And so this allows the compiler to optimize the code. 16 00:01:28,430 --> 00:01:31,100 So I want to write another example here. 17 00:01:32,030 --> 00:01:32,720 Let's. 18 00:01:34,320 --> 00:01:37,680 Where I can triangle function here. 19 00:01:38,660 --> 00:01:39,080 Here. 20 00:01:40,010 --> 00:01:41,040 Close to expiration. 21 00:01:41,040 --> 00:01:47,160 So as you can see, this keyboard can be used in functions here and integer. 22 00:01:47,160 --> 00:01:49,350 This takes integer as parameter. 23 00:01:50,130 --> 00:01:54,690 Lets return E equals. 24 00:01:54,690 --> 00:01:59,490 If E equals zero here, you will learn about this later. 25 00:01:59,850 --> 00:02:00,840 What is this? 26 00:02:02,070 --> 00:02:12,540 Just write it and in next lecture you will learn the return statements and what these are in next lecture. 27 00:02:12,540 --> 00:02:19,170 So don't worry, You will learn about all of them here and the key here. 28 00:02:19,950 --> 00:02:26,790 So in this example, the function triangle triangle try inch. 29 00:02:26,820 --> 00:02:31,410 You'll calculate triangular numbers recursively. 30 00:02:31,500 --> 00:02:35,100 So the code uses the conditional operator here. 31 00:02:35,220 --> 00:02:44,670 So in this parenthesis, the function parameter is tested to see if it is a zero here, if it is zero 32 00:02:44,670 --> 00:02:47,390 and if so, the function returns zero. 33 00:02:47,400 --> 00:02:53,470 In fact, ending the reclusion and returning the function to the original color. 34 00:02:53,490 --> 00:03:00,990 So if the parameter is not zero here, then the return value is the sum of the parameter. 35 00:03:00,990 --> 00:03:09,400 And the return value of trying count with the parameter is decrement by one, as you can see here. 36 00:03:09,420 --> 00:03:15,660 So this function when called with a literal in your code can be evaluated at the compile time. 37 00:03:15,780 --> 00:03:23,610 So the cost expert here is an indication to the compiler to check the usage of the function to see if 38 00:03:23,610 --> 00:03:27,120 it can determine the parameter at the compile time. 39 00:03:27,120 --> 00:03:35,460 So if this is the case, the compiler can evaluate the return value and produce more offense efficiency 40 00:03:36,240 --> 00:03:38,460 than by calling the function at runtime. 41 00:03:38,460 --> 00:03:44,310 So if the compiler cannot determine the parameter at the compile time, the function then the called 42 00:03:44,310 --> 00:03:46,020 as just the normal. 43 00:03:46,020 --> 00:03:54,810 So a function marked with the cost x per here keyword must only have one expression and the use of the 44 00:03:54,810 --> 00:03:59,460 conditional operator here as you can see here in the trunk function.