Structure: Compound Operators Flashcards

1
Q

Increment and Decrement

A

++ & –

Syntax

x++; // increment x by one and returns the old value of x

++x; // increment x by one and returns the new value of x

x– ; // decrement x by one and returns the old value of x

–x ; // decrement x by one and returns the new value of x

Examples

x = 2;
y = ++x; // x now contains 3, y contains 3
y = x--; // x contains 2 again, y still contains 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Allows you to perform a mathematical operation through a shorthanded way.

A

+=, -=, *=, /=, %=

Syntax

x += y; // equivalent to the expression x = x + y;

x -= y; // equivalent to the expression x = x - y;

x *= y; // equivalent to the expression x = x * y;

x /= y; // equivalent to the expression x = x / y;

x %= y; // equivalent to the expression x = x % y;

Examples

x = 2;
x += 4; // x now contains 6
x -= 3; // x now contains 3
x *= 10; // x now contains 30
x /= 2; // x now contains 15
x %= 5; // x now contains 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

used with a variable and a constant to force particular bits in a variable to the LOW state (to 0). This is often referred to in programming guides as “clearing” or “resetting” bits.

Used with variable often to set to one.

A

x &=, x |=

Syntax Compound &:

x &= y; // equivalent to x = x & y;

Parameters

A character, int or long variable

Example: Look online

Syntax Compound or

x |= y; // equivalent to x = x | y;

Example:

0 0 1 1 operand1

0 1 0 1 operand2

0 1 1 1 (operand1 | operand2) - returned result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly