Computer Science, asked by sivabalan14, 1 year ago

write the 2 forms of type conversion facilitated by c++.also give suitable example of each​

Answers

Answered by vaibhavkr4337
1

Answer:

Two types of conversion in C++ are:

(1) Implicit Type Conversion - This type of conversion takes place automatically by the compiler whenever required without the programmer's intervention.

Example, suppose we are writing an expression like this:

     2.0+3

So, here, 2.0 is float while 3 is int. Thus, the compiler needs to convert this expression in a single type. In this case, 3 is converted to float, and the output will be 5.0 and not 5.

There is a specific order of data types which is followed by the compiler for implicit conversion:-

bool -> char -> short int -> int ->  

unsigned int -> long -> unsigned ->  

long long -> float -> double -> long double

(2)Explicit Type Conversion - This type of conversion done by a programmer forcibly from one data type to another type.

SYNTAX:-

(type) expression/variable

Suppose, we have to convert 3.4 to int, we will write:

(int) 3.4

HOPE MY ANSWER HELPS :)

Similar questions