Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

C++Arduino is based C++, which has large 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.

The Rules For Declaring Variable:

  1. Variable names only contain letters, digits, and underscores

  2. Variable names are case sensitive

  3. Variable names do not contain any whitespace and special characters (for example: #, *, % etc).

  4. Variable names must begin with a letter or an underscore.

  5. We can't use Arduino or C++ keywords as a variable name (for example: void, setup, int)

Arduino Variables

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;

...

I.e. Unsigned Int x = 65 500;

Additional C++ Variables

byte

int

uint

long

ulong

double

Floating Point number 
I.e. double y = 1.234;

char
Character 
I.e. char z = “a”;

String
A collection of characters 
I.e. String testString = “Arduino”;

boolean
A binary variable
I.e. boolean state = false; (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