Compound operators in Arduino


Compound operators in Arduino work just like in C, and they help save you some writing time, and also reduce the number of lines in your code. As the name seems to suggest, compound operators combine multiple operators.

The following table lists the compound operators in Arduino.

Assume that a and b are integers having values a = 5 and b = 2 in all the following examples −

OperatorDescriptionExampleOutput
++Incrementa++a=6
--Decrementa--a=4
+=Compound Additiona+=ba=7
-=Compound subtractiona-=ba=3
*=Compound multiplicationa*=ba=10
/=Compound divisiona/=ba=2
%=Compound remaindera%=ba=1
&=Compound bitwise ANDa&=ba=0
|=Compound bitwise ORa|=ba=7
^=Compound bitwise XORa^=ba=7


Updated on: 31-Jul-2021

323 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements