Skip to main content

Type conversion

Types belonging to the same category as well as different currencies can be converted to each other. Type conversion (typecasting) is the process of converting (converting) a value of one type to a value of another type.

Type conversions are divided into explicit and implicit conversions.

Implicit conversions#

Implicit conversions do not require any language constructs and do not lead to data loss. An example of an implicit conversion is converting a value of type int to type double. Being a 64-bit real type, double can store any value of a 32-bit integer type int.

inttodouble

As shown in the image above, converting an int to a double does not result in data loss, since a 32-bit value fits into 64 bits.

Explicit conversions#

Explicit conversions, often referred to as typecasting for clarity, take place with developer input and require the specification of language constructs called cast operators. Typecasting is required when data may be lost during the conversion process or, for some reason, the process may end with an error. The simplest example of an explicit conversion is the conversion of the double type, used to store 64-bit floating point values, to the integer type int.

doubletoint

Payment#

Now you are on a stripped-down version of the site, after subscribing to Patreon, you will get full access to the training course, as well as access to our server's private channels in Discord.

Download our mobile application or get tested in our JavaScript telegram bot, and also subscribe to our news.

Become a Patron!

Sumerian school

Contributors โœจ#

Thanks goes to these wonderful people (emoji key):


Philipp Dvinyaninov

๐Ÿ“–

Dmitriy Vasilev

๐Ÿ’ต

Become a Patron!