arduino datatypes

Effective coding techniques in Arduino: More about datatypes

This entry is part 3 of 8 in the series Arduino Tips & Tricks

In programming, datatype is a classification which specifies which type of value a variable is assigned with and what type of mathematical, relational or logical operations can be applied to it.

Some of the datatypes regularly used in Arduino are given below. The chart shows the memory and range of the datatypes also.

image 22 Vidyasagar Academy Akola

About int datatype

Integers are the primary datatype for storage of numbers without decimal points and store a 16-bit value with a range of 32,767 to -32,768.

int variable_name = 1500; // declares 'variable_name' as an integer type

Note: Integer variables will roll over if forced past their maximum or minimum values by an assignment or comparison.

For example, if x = 32767 and a subsequent statement adds 1 to xx = x + 1 or x++x will then rollover and equal -32,768.

About long datatype

Extended size datatype for long integers, without decimal points, stored in a 32-bit value with a range of 2,147,483,647 to -2,147,483,648.

long variable_name = 90000; // declares 'variable_name' as a long type

About float datatype

It is a datatype used for floating-point numbers or numbers that have a decimal point. The floating point numbers have greater resolution and accuracy than integers and they are stored as 32-bit value with the range from 3.4028235E+38 to -3.4028235E+38.

float pi = 3.1415926; // declares pi' as floating-point type

Note: The floating-point numbers are not exact and may produce strange results when compared. Floating point math is also much slower than integer math while performing calculations.

Share on your network!
Dattaraj Vidyasagar
Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 35+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 17 books on electronics, robotics, programming languages and web designing... ➤➤

Leave a Reply

Your email address will not be published. Required fields are marked *