Compound Assignment

Note that Compound assignment to an enumerated type generates an error message.

If the left operand is of a pointer type, the right operand must be of a pointer type or it must be a constant expression that evaluates to 0.

Each compound-assignment operator performs the conversions that the corresponding binary operator performs and restricts the types of its operands accordingly.In this chapter and the next, we present the theory and principles of structured programming with control statements.We introduce the control and use it to display and process data, such as a list of grades in a class-average program.That information, along with your comments, will be governed by DISQUS’ privacy policy.By commenting, you are accepting the DISQUS terms of service.One of the reasons compound operators are useful is that not only they provide a shorter way for operations, but also implicitly cast variables.Formally, a compound assignment expression of the form: Let’s review why the last line won’t compile.It is very common to have an assignment statement only involving one operation and two values where the result replaces the original value, such as: a = a 3; b = b * c; C and C offer several convenient shortcuts to such statements. The above two assignments may be replaced by: a = 3; b *= c; The = and *= are two of many instances of compound assignment operators. The operator ' ' does the binary numeric promotion to its operands, using Widening Conversion to convert operands as necessary. "short y =1; y = y 1;" doesn't compile is because of the so called Binary Numeric Promotion.For y = y 1, is int, so y is converted to an int, the result of y 1 is also of type int.

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “Compound Assignment”

  1. You should have at least three paragraphs’ worth of evidence for your argument, and if you do not, it’s likely that your thesis isn’t strong enough.