CHAPTER 15

image

Type Conversions

Converting an expression from one type to another is known as type casting or type conversion. This can be done either implicitly by the compiler or explicitly with code.

Implicit Conversions

An implicit conversion is performed automatically by the compiler when an expression needs to be converted into one of its compatible types. For example, any conversions between the primitive data types can be done implicitly.

long l = 5;   /* int -> long */double d = l; /* long -> double */

These implicit conversions can also take place within an expression, allowing you to mix different primitive types together. When types of ...

Get C Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.