Integer

The integer is the primary data type used to store numerical data when a decimal value is not needed. A variable of the integer type can contain numbers ranging from -32,768 to 32,768. An integer is defined using the int keyword.

We can declare an integer to be unsigned by using the unsigned keyword. An unsigned integer can range from 0 to 65,535 whereas the normal integer has a range of -32,768 to 32,768. The following code shows how we would define both a regular integer and an unsigned integer:

int mySignedInt = 25;
unsigned int myUnsignedInt = 15;

In the preceding code, we declared a variable named mySignedInt of the integer type with an initial value of 25. We also declared a second variable named myUnsignedInt of the unsigned ...

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.