Arduino Compound Operators Arduino

What is Arduino Compound Operators?

Assume variable A holds 10 and variable B holds 20 then −

Operator name

Operator simple

Description

Example

increment

++

Increment operator, increases integer value by one

A++ will give 11

decrement

--

Decrement operator, decreases integer value by one

A-- will give 9

compound addition

+=

Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand

B += A is equivalent to B = B+ A

compound subtraction

-=

Subtract AND assignment operator. It subtracts right operand from the left operand and assign the result to left operand

B -= A is equivalent to B = B - A

compound multiplication

*=

Multiply AND assignment operator. It multiplies right operand with the left operand and assign the result to left operand

B*= A is equivalent to B = B* A

compound division

/=

Divide AND assignment operator. It divides left operand with the right operand and assign the result to left operand

B /= A is equivalent to B = B / A

compound modulo

%=

Modulus AND assignment operator. It takes modulus using two operands and assign the result to left operand

B %= A is equivalent to B = B % A

compound bitwise or

|=

bitwise inclusive OR and assignment operator

A |= 2 is same as A = A | 2

compound bitwise and

&=

Bitwise AND assignment operator

A &= 2 is same as A = A & 2

Example

Result

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Arduino Topics