Addition is one of the four primary arithmetic operations. The operator + (plus) operates on two operands to produce the sum.
Syntax
sum = operand1 + operand2;
Parameters
sum : variable. Allowed data types: int, float, double, byte, short, long operand1 : variable or constant. Allowed data types: int, float, double, byte, short, long operand2 : variable or constant. Allowed data types: int, float, double, byte, short, long
Example Code
int a = 5;
int b = 10;
int c = 0;
c = a + b; // the variable 'c' gets a value of 15 after this statement is executed
Notes and Warnings
The addition operation can overflow if the result is larger than that which can be stored in the data type (e.g. adding 1 to an integer with the value 32,767 gives -32,768).
If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation.
If the operands are of float / double data type and the variable that stores the sum is an integer, then only the integral part is stored and the fractional part of the number is lost.
float a = 5.5;
float b = 6.6;
int c = 0;
c = a + b; // the variable 'c' stores a value of 12 only as opposed to the expected sum of 12.1
See also
Title
Arduino Newsletter
We care about the privacy and personal data of our users.
To continue, please give us your consent:
Please confirm that you have read the privacy policy
Thank you for subscribing!
Curious to learn more?
Are you also a teacher, student, or professional that loves using Arduino in your day-to-day activities?
Then keep up-to-date with either our STEM or Professional monthly newsletters.
Arduino weekly newsletter (already subscribed)
Educators can benefit from the ever growing tech that shapes our environment through fun cool projects.
Why not awe your boss with highly innovative ways to help keep your enterprise connected at no extra cost?
Arduino Survey
We'd like to get to know you little better.
Please help us improve by answering this super short optional survey.