From the course: C Essential Training
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Compound assignment operators - C Tutorial
From the course: C Essential Training
Compound assignment operators
- [Instructor] C supports compound assignment operators that allow you to combine an assignment with an arithmetic operation. These are both convenient and efficient. This is operators.cpp from chapter five of the exercise files. We'll come down here and we'll simply create a compounded assignment operator. So what this does is this adds Y to X. It's exactly the same as X equals X plus Y, with the difference that with the compound operator, X is only evaluated once. And this is a distinction that may make a difference under some circumstances. So it's good to be aware of. But otherwise, it's exactly the same. So if I come down here and I print out X after the operation, we'll go ahead and run this. You see that after our compound assignment, X is now 52. We've added the value of Y to X. There's five different compound assignment operators, there's plus equals, there's minus equals. So if I go ahead and run that,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.