Arithmetic functions

The Arduino programming language includes operators that enable us to calculate the sum, difference, product and quotient of two operands. To use these operators, the two operands must be of the same type. This means, as an example, we have the ability to calculate the sum of two integer variables; however, we are unable to calculate the sum of a float variable and an integer variable without casting one of the variables forcing them to be of the same type. We will look at casting a little later in this chapter.

The following example shows how we calculate the sum, difference, product, and quotient of two variables:

z = x + y; // calculates the sum of x and y z = x - y; // calculates the difference of x and y z = x * ...

Get Mastering Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.