1 00:00:05,800 --> 00:00:10,250 In this video, we'll learn about c++'s compound assignment operators. 2 00:00:11,050 --> 00:00:15,050 These operators are very easy to use and commonly used in c++ code. 3 00:00:16,040 --> 00:00:18,500 The syntax for the operators is pretty simple. 4 00:00:18,500 --> 00:00:22,100 It's the operator you wish to use immediately followed by an equal sign. 5 00:00:23,000 --> 00:00:27,100 There are quite a few of these operators, but we'll focus on the mathematical operators. 6 00:00:27,100 --> 00:00:31,650 The bottom half of this table includes the operators that are used to manipulate bits. 7 00:00:31,900 --> 00:00:35,400 They're called bitwise operators. And I'll cover them later in this course. 8 00:00:35,950 --> 00:00:39,250 So let's look at the first one in the table. The plus equal operator. 9 00:00:39,750 --> 00:00:42,450 We apply the operator as in the example column. 10 00:00:42,450 --> 00:00:45,950 For example, left-hand side plus equals right-hand side. 11 00:00:46,350 --> 00:00:49,450 The meaning of this would be to increment the left-hand side 12 00:00:49,450 --> 00:00:50,950 by the right-hand side 13 00:00:50,950 --> 00:00:54,150 and then store the resulting value in the left-hand side. 14 00:00:54,850 --> 00:00:57,350 We'll see a few real code examples in the next slide. 15 00:00:57,850 --> 00:01:00,150 All of these operators work the same way. 16 00:01:00,150 --> 00:01:04,450 For example, the multiplication equal operator multiplies the left-hand side 17 00:01:04,450 --> 00:01:08,450 by the right-hand side and stores the product back in the left-hand side. 18 00:01:08,450 --> 00:01:09,750 Let's see some examples. 19 00:01:11,750 --> 00:01:15,750 Here we see some examples of using several of the compound assignment operators. 20 00:01:16,250 --> 00:01:19,570 Let's look at the first example. A plus equals one. 21 00:01:20,170 --> 00:01:23,730 This means increment the left-hand side by the right-hand side 22 00:01:23,730 --> 00:01:26,830 and store the result back into the left-hand side. 23 00:01:26,830 --> 00:01:30,390 So this is the same as a equals a plus one. 24 00:01:30,390 --> 00:01:33,090 And it's another way of incrementing a variable by one. 25 00:01:34,090 --> 00:01:38,390 The second example works exactly the same way except that we'll be dividing the 26 00:01:38,390 --> 00:01:42,590 a by 5., then storing the result back into a. 27 00:01:43,190 --> 00:01:46,890 The third example shows how the entire right-hand side is evaluated 28 00:01:46,890 --> 00:01:48,790 before the operator is applied. 29 00:01:49,190 --> 00:01:52,550 In this case, we have a multiplication equal 30 00:01:52,550 --> 00:01:53,910 b plus c. 31 00:01:53,910 --> 00:01:57,910 This means multiply a by the sum of b plus c. 32 00:01:58,310 --> 00:02:00,610 Then store the product back in a. 33 00:02:01,010 --> 00:02:05,900 In the last example, we're incrementing cost by the product of item and tax. 34 00:02:06,900 --> 00:02:11,200 The best tip I can give you when you write these operators is to think of the right-hand side 35 00:02:11,200 --> 00:02:14,500 as being inside parentheses and you'll always have it right.