Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
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;