1

00:00:01,140  -->  00:00:06,570
So you look at the different arithmetic operators there are not a few rolls that may come into play

2

00:00:06,750  -->  00:00:09,450
when using arithmetic operations.

3

00:00:09,450  -->  00:00:11,550
Knowing these rules is very important.

4

00:00:11,670  -->  00:00:14,700
And let's look at what these rules are.

5

00:00:15,330  -->  00:00:21,240
We can have instances where we come across expressions such as this which have more than one otic Medek

6

00:00:21,240  -->  00:00:22,240
operation.

7

00:00:22,680  -->  00:00:24,310
So it's a compound expression.

8

00:00:24,540  -->  00:00:29,250
But the question is in what order are the subexpressions evaluated.

9

00:00:29,400  -->  00:00:36,090
That is what the first ad 5:01 line or would do for us multiply 2 and 5 and then add the result to 3

10

00:00:37,230  -->  00:00:42,900
dollar has a couple of set rules called operator precedence rules for this kind of compound expression

11

00:00:42,900  -->  00:00:45,220
.

12

00:00:45,240  -->  00:00:51,810
First rule is that multiplicative operators have higher precedence over any two operators multiplicative

13

00:00:51,810  -->  00:00:57,030
Operators Group multiplication division and Margulis whereas any two operators include addition and

14

00:00:57,030  -->  00:01:02,140
subtraction with just one example expression but looks something like this.

15

00:01:02,730  -->  00:01:10,020
That is to an Freiler multiplied first as multiplication has higher presidents once the first rule is

16

00:01:10,020  -->  00:01:10,640
applied.

17

00:01:10,740  -->  00:01:17,250
Then the second rule is that operators within the same group will be evaluated from left to right and

18

00:01:17,250  -->  00:01:21,600
by applying this rule on our example expression we would have something like this.

19

00:01:21,750  -->  00:01:27,330
That is all left to what operators belong to the same group which is additive two operators group and

20

00:01:27,330  -->  00:01:29,650
so they are evaluated from left to right.

21

00:01:30,240  -->  00:01:37,260
So 9 or are that first then three is subtracted from the desert and a new reserve is finally added to

22

00:01:37,400  -->  00:01:40,610
do in to fight.

23

00:01:40,680  -->  00:01:45,590
Finally note that you can use pattern sources to change the order of evaluation.

24

00:01:45,660  -->  00:01:50,290
So in our example we can force the expression to be evaluated this way.

25

00:01:50,550  -->  00:01:57,060
He had 3 and 2 and 5 or 9 will be added separately but the sum of three and two will be multiplied with

26

00:01:57,060  -->  00:02:03,760
5 due to rule 1 and the result will be proctored from five plus nine.

27

00:02:03,900  -->  00:02:06,160
Next is open and promotion rule.

28

00:02:06,450  -->  00:02:09,170
That is it has something to do with promoting an operator.

29

00:02:09,390  -->  00:02:11,540
Let's see what it is.

30

00:02:12,120  -->  00:02:20,280
It states that operate in smaller than and that is byte shot or car are promoted to and hit Here's an

31

00:02:20,280  -->  00:02:21,390
example.

32

00:02:21,600  -->  00:02:25,260
Here is the Ajume that the two operands of by date type.

33

00:02:25,410  -->  00:02:30,460
Then they will be first promoted to end before any operation is applied.

34

00:02:31,470  -->  00:02:32,910
And here is another example.

35

00:02:32,910  -->  00:02:33,700
The carburetor.

36

00:02:33,740  -->  00:02:42,390
I recall that card Streater I said 16 bit unsigned integer whose range is zero to the power of 16 minus

37

00:02:42,390  -->  00:02:43,150
one.

38

00:02:43,670  -->  00:02:48,310
So if God is used an IT operation it will also be promoted to an end.

39

00:02:48,780  -->  00:02:49,750
So in this example.

40

00:02:49,770  -->  00:02:53,940
Characters IA and B are promoted to the respective decimal values.

41

00:02:54,000  -->  00:02:57,690
97 98 and you of 16.

42

00:02:57,690  -->  00:02:59,800
So the final result will be 195.

43

00:03:00,450  -->  00:03:06,330
Shortly we will also be a quick demo where we will see examples of current use getting promoted to and

44

00:03:09,300  -->  00:03:15,450
next let's look at another rule which we can refer to as same type operations rule and this rule states

45

00:03:15,450  -->  00:03:23,190
that if both our parents are in long float our bubble then the arithmetic operation is carried out in

46

00:03:23,190  -->  00:03:28,060
that type and also evaluated the value of that same day.

47

00:03:28,950  -->  00:03:34,220
Here are a couple of examples where the operands are integers in the second example.

48

00:03:34,290  -->  00:03:40,260
Even though the characters are at this point fine the value return will be zero as spawn 5 is not an

49

00:03:40,260  -->  00:03:41,200
integer.

50

00:03:41,310  -->  00:03:43,900
So point five was truncated to zero.

51

00:03:45,120  -->  00:03:51,150
Previous rule was called same type operations stored on the operations but of SAME TIME NEXT rule is

52

00:03:51,150  -->  00:03:56,310
about operands being of different types and so is referred to as mixed type operations.

53

00:03:56,310  -->  00:03:58,640
Let's see what it states.

54

00:03:59,130  -->  00:04:05,400
It states that if both operands belong to different types then the value of the smaller type is automatically

55

00:04:05,400  -->  00:04:08,780
promoted to larger type.

56

00:04:09,000  -->  00:04:11,270
And here is the order of promotion.

57

00:04:11,270  -->  00:04:17,540
Note that if you have long and flautas operands longest promoted to float even though long 64 bit untrue

58

00:04:17,550  -->  00:04:19,750
disturbed little bit.

59

00:04:20,600  -->  00:04:26,700
Here is a similar example as in the previous light did BORTOLI draws 1 and 2 are integers and so the

60

00:04:26,700  -->  00:04:29,730
result was also an integer which was 0.

61

00:04:30,120  -->  00:04:36,670
Here in both examples one of the operands is a double and so due to this particular rule the interior

62

00:04:36,670  -->  00:04:43,970
operand is promoted to double and so the final result is a double value point five.

63

00:04:44,010  -->  00:04:50,830
Here is how an expression involving a car and float are evaluated got is first promoted to and the operand

64

00:04:50,850  -->  00:04:52,160
promotion rule.

65

00:04:52,290  -->  00:04:55,000
Then it is promotor to float DUPERE this rule.

66

00:04:55,200  -->  00:04:59,520
And finally both the floats will be added on.

67

00:04:59,550  -->  00:05:02,660
Here is a very nice example in this expression.

68

00:05:02,700  -->  00:05:09,570
First division operation is applied as both operators are from the same group that is belong to multiplicative

69

00:05:09,630  -->  00:05:13,500
Operators Group and hence are evaluated from left to right.

70

00:05:13,680  -->  00:05:17,180
So that's the operator president's rule in action.

71

00:05:17,190  -->  00:05:23,130
Next since 9 and 5 are in the first same type operations rule is applied and the result of division

72

00:05:23,220  -->  00:05:25,980
will be an integer value 1.

73

00:05:25,980  -->  00:05:32,460
No we are left with integer under double N since integers are smaller they are tight due to mixed type

74

00:05:32,460  -->  00:05:33,230
operations.

75

00:05:33,240  -->  00:05:38,680
When it gets promoted to double and the final result will be double.

76

00:05:38,720  -->  00:05:45,930
In general the largest data type in an expression determines the type of the final result.

77

00:05:45,930  -->  00:05:51,340
Now as mentioned earlier let's do a quick them off Oper in promotion rule a new method called Cartaya

78

00:05:51,350  -->  00:05:56,970
promotion has been added to basics demo class which can be downloaded from the resources section.

79

00:05:56,970  -->  00:05:59,360
Let's look at the program now.

80

00:06:00,660  -->  00:06:06,360
OK here is the numerator cark by promotion and it's invoked from the main method and there are a bunch

81

00:06:06,360  -->  00:06:07,960
of print statements here.

82

00:06:08,220  -->  00:06:13,350
So let's just go ahead and run this program and we will look at the Outlook and then we will discuss

83

00:06:13,350  -->  00:06:14,470
the print statements.

84

00:06:14,480  -->  00:06:19,430
Ok ok so I'm already in the basics directory so let me just run it.

85

00:06:19,440  -->  00:06:20,920
It's already compiled.

86

00:06:21,420  -->  00:06:22,820
So here is the output.

87

00:06:23,030  -->  00:06:27,990
Let's just look at that last statement because it was already covered in the in the slight.

88

00:06:28,300  -->  00:06:35,990
So it's just printing it just adding two characters a and b and the output is 195.

89

00:06:36,340  -->  00:06:39,150
And that's because off the operand promotional.

90

00:06:39,210  -->  00:06:44,400
So that's because here we have two characters on both the characters as we discussed will be promoted

91

00:06:44,400  -->  00:06:53,220
to integers so the corresponding integer values and UAD of 16 is 97 98 and so you'll see the final value

92

00:06:53,220  -->  00:06:55,110
as the same as 1 95.

93

00:06:55,260  -->  00:07:00,920
OK so that's what is happening even even though you're adding two characters here.

94

00:07:00,990  -->  00:07:08,030
Now the first one is very simple it's simply printing the carbon carbon is basically is assigned a decimal

95

00:07:08,050  -->  00:07:13,590
50 so decimal 50 is equal to you'd be up in uk of 16 its value.

96

00:07:13,890  -->  00:07:15,850
So if you see here it's printing do.

97

00:07:15,900  -->  00:07:18,330
We already know that from our characters demo.

98

00:07:18,780  -->  00:07:20,310
So it's just printing too.

99

00:07:20,490  -->  00:07:26,000
So carbon is basically to write on the second print statement here.

100

00:07:26,130  -->  00:07:33,240
It's subtracting carbon from 73 so it's 73 minus carbon carbon is basically two.

101

00:07:33,600  -->  00:07:40,100
So it gets promoted to án And so the equal in decimal value is once again 50 so it's going back to 50

102

00:07:40,160  -->  00:07:40,450
.

103

00:07:40,680  -->  00:07:42,790
So it would be 73 minus 50.

104

00:07:43,010  -->  00:07:48,630
And so we are seeing 23 as the final 73 minus 50.

105

00:07:48,720  -->  00:07:55,230
So in the next print statement we are doing we are subtracting character 3 from carbon.

106

00:07:55,320  -->  00:07:58,570
So carbon has two and this is three.

107

00:07:58,720  -->  00:07:59,540
So.

108

00:07:59,560  -->  00:08:05,270
So both of them are characters essentially and both of them get promoted to two.

109

00:08:05,290  -->  00:08:10,420
And so carbon will get promoted to end and the value will be 50.

110

00:08:10,470  -->  00:08:13,930
And since this is three it will get promoted to 51.

111

00:08:14,250  -->  00:08:16,640
So 51 us 51 us minus 1.

112

00:08:16,730  -->  00:08:18,320
And that's what we see here.

113

00:08:18,690  -->  00:08:19,620
OK.

114

00:08:19,620  -->  00:08:21,830
So that's the operant promotion run.

115

00:08:22,080  -->  00:08:25,490
And so basically we look at that four kinds of rules.

116

00:08:25,500  -->  00:08:32,400
One is to operate or presidents run then operate in promotion rule then same type operations rule and

117

00:08:32,790  -->  00:08:34,350
Mixter type operations.

118

00:08:34,460  -->  00:08:35,040
OK.

119

00:08:35,070  -->  00:08:36,360
So these are very important.

120

00:08:36,360  -->  00:08:43,980
So please do understand them very well and you can also expect some questions in the quest for him from

121

00:08:43,980  -->  00:08:45,060
this particular lesson.

122

00:08:45,060  -->  00:08:45,490
OK.

123

00:08:45,540  -->  00:08:51,210
And you can also download this program and play around really familiarize yourself with with the with

124

00:08:51,210  -->  00:08:52,050
this lesson.

125

00:08:52,350  -->  00:08:52,650
OK.

126

00:08:52,660  -->  00:08:53,360
And thank you.

127

00:08:53,380  -->  00:08:54,750
And happy coding.
