O'Reilly logo

Mastering Arduino by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Casting

The cast operator will convert the variable type to a different type. This will enable us to perform operations, like arithmetic operations, on variables of different types. For example, if we want to add two variables where one is of the float type and the other is of the integer type, then we will need to cast one of them, so the two variables are of the same type.

One thing to note is when we cast a float value to an integer value the value is truncated and not rounded. This means that if the float variable contains the value 2.9 and we cast it to an integer, the value will be 2. With this in mind, we generally want to cast integer values to float values rather than float values to integer values even if it means the operation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required