Compound Assignment Operator

3 minutes
Share the link to this page
Copied
  Completed
Compound-assignment operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. They perform the operation on the two operands before assigning the result to the first operand.

Transcript

Hello and welcome to the 11th tutorial in the c++ programming series and in this part we're going to be looking at the compound assignment operator, a complex assignment operator that allow you to modify variables current value by performing an operation on it, it is essentially equivalent to assigning the result of the operation to the variable First, let's go ahead and open up our project. And there are four timer operators that we're going to look at for compound sign operated on okay now I should say, and the first one is plus equals like and one is minus the fourth. One is to avoid cause and the fourth form is time decay equals. So what these do so let's create a variable First and oh equals for you and if we put i plus equals 10 This is the equivalent to saying that I the course itself plus 10 hands it will now be 15 so if we just do STD c I'm gonna put or run this and with the build succeeded annotated 15 versus comment this I've second or like put this boy at the end here.

The minus equals oh don't do it minus equals 20 is the equivalent to oil it goes It's out minus 20. You can write that there, but it is a shortened version of it. So I wouldn't have been minus 15. I think we've seen I think you should be seeing a pattern here by now. So I divided by two do buy flights into a lot easier to see what is happening. This is the equivalent to all equals I aka itself.

Boy, boy five. If we run it, we'll get one common this And the final one is, is I equals I mean, time equals five equivalent of i equal itself time by five, so it will be 25. So yeah, that is the compound assignment operator. They are really useful. I like to try code and when you're working on our code, anything that helps you show today is is great. So yeah that's it for this tutorial.

If you have any questions feel free to message us or support us on our system coda UK. email will be in the description you can comment on this video or historically messages via YouTube or the recording for source code will also be in the description. The next tutorial we'll look at increment and decrement operators and thank you for watching

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.