﻿# Implicit type conversion

Implicit type conversion, also known as "coercion", is an automatic type conversion by the compiler\. Implicit conversions do not require any operator\. They are automatically performed when a value is copied to a compatible type\. In a mixed type expression, a subtype s will be converted to a supertype t or some subtypes s1, s2, \.\.\. will be converted to a supertype t \(maybe none of the s\{i\} is of type t\) at runtime so that the program will run correctly\. For example:

```cpp
double d;
long l;
int i;
if (d > i)
  d = i;
if (i > l)
  l = i;
if (d == l)
  d *= 2;
```

Although d, l and i belong to different datatypes, they will be automatically converted to the same datatype each time a comparison or assignment is executed\.

## References

1. Wikipedia\. Type conversion\. [https://en\.wikipedia\.org/wiki/Type\_conversion\#Implicit\_type\_conversion](https://en.wikipedia.org/wiki/Type_conversion#Implicit_type_conversion)