Arduino is based C++, which has a number of variable types available to us, and some special variables tricks that can be a little confusing but also very helpful when programming microcontrollers.
Variable names only contain letters, digits, and underscores
Variable names are case sensitive
Variable names do not contain any whitespace and special characters (for example: #, *, % etc).
Variable names must begin with a letter or an underscore.
We can't use Arduino or C++ keywords as a variable name (for example: void, setup, int)
int (2 bytes on uno and other ATMEGA based boards, 4 bytes on SAMD boards)
A whole number between -32 768 and the max value is +32 767.
I.e. int x = 22;
float (4 bytes)
Floating Point number between 3.4028235E+38 to -3.4028235E+38
I.e. float y = 1.234;
char (1 byte)
A char simply stores a value between -128 and +127, but it’s normally used to represent a character
I.e. char z = “a”;
String (many bytes)
A collection of characters. The String is a class, not a primitive data type and it’s specific to Arduino. It provides a simpler alternative to creating an array of chars, and provides some extra functionality
I.e. String testString = “Arduino”;
boolean/bool (1 bit)
A binary variable, that stores either a 1 or a 0. You can can use either boolean or bool.
The 1 or 0 are typical represented as true and false.
I.e. bool state = false;
Unsigned modifier.
Some variables can be combined with the unsigned modifier. An unsigned value means that it no longer has negative or positive indicator. For example, and unsigned int can have a value between 0 and have a max value of 65 535
I.e. Unsigned Int x = 65 500;
byte (1 byte) A single byte of storage i.e a value between -128 and +127,
long (4 to 8 bytes) Like an int, but with twice as much storage
double (4 to 8 bytes) Like a float, but with twice as much storage