Explicit Types Conversions (Typecasting)
In most situations, compiler will provide an automatic implicit conversion of types where needed, without any user's interference. Also, the user can explicitly convert an operand to another type using the prefix unary typecast operator:
(type) object
This will convert object
to a specified type
. Parentheses are mandatory.
For example:
/* Let's have two variables of char type: */ char a, b; /* Following line will coerce a to unsigned int: */ (unsigned int) a; /* Following line will coerce a to double, then coerce b to double automatically, resulting in double type value: */ (double) a + b; // equivalent to ((double) a) + b;
Copyright (c) 2002-2013 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
What do you think about this topic ? Send us feedback!