Mikroelektronika MIKROE-738 Datenbogen
![Mikroelektronika](https://files.manualsbrain.com/attachments/e0529b3b58069a916ad7bb89f7e9f5f0eda73421/common/fit/150/50/1b07b99aa3112e022a916b06db07f1f4f211e91d41878452d87c7638b1bf/brand_logo.gif)
mikroC PRO for PIC32
MikroElektronika
221
Here are several examples of implicit conversion:
2 + 3.1 /* → 2. + 3.1 → 5.1 */
5 / 4 * 3. /* → (5/4)*3. → 1*3. → 1.*3. → 3. */
3. * 5 / 4 /* → (3.*5)/4 → (3.*5.)/4 → 15./4 → 15./4. → 3.75 */
Pointer Conversions
Pointer types can be converted to other pointer types using the typecasting mechanism:
char *str;
int *ip;
str = (char *)ip;
More generally, the cast
type*
will convert a pointer to type “pointer to
type
”.
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;