A type cast is basically a conversion from one type to another. There are two types of type conversion:
- Implicit Type Conversion Also known as ‘automatic type conversion’.
Example of Type Implicit Conversion:
x = 10;
x = x + y;
z = x + 1.0;
"x = "
<< x << endl
"y = "
<< y << endl
"z = "
<< z << endl;
x = 107
y = a
z = 108
- Explicit Type Conversion: This process is also called type casting and it is user-defined. Here the user can typecast the result to make it of a particular data type.
In C++, it can be done by two ways:
Advantages of Type Conversion:
- This is done to take advantage of certain features of type hierarchies or type representations.
- It helps to compute expressions containing variables of different data types.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!