Computer Science, asked by yamunonu3630, 1 year ago

Give the difference between type casting and automatic type conversion give suitable examples

Answers

Answered by saitejassb
3
Automatic Type Conversion

IN C++  an automatic type casting  or implicit type conversion is a type of data type conversion which is  performed by the compiler on its own. It basically occurs whenever an expression has different data type .In this type of conversion , the data type which are smaller are converted into larger data type to avoid data loss.  

Example:

int x=3,y=1,c;
float p=11.5,q;
q=p/x;

In the above case the expression p/x, x's type will automatically be promoted to bigger type float  and then the expression will be evaluated .

TYPE CASTING 

The type casting or explicit type conversion  is user - defined forced conversion . It is basically done with the help of operator ( ) called as casting operator . 

Example:

float p=(float) 22/7;

Explanation 

Then 22 will be first converted to float type and this expression will get  evaluatedType conversion

Type conversion occurs when the expression has data of mixed data types. 

example of such expression include converting an integer value in to a float value, or assigning the value of the expression to a variable with different data type.

In type conversion, the data type is promoted from lower to higher because converting higher to lower involves loss of precision and value.

For type conversion, C following some General rules explained below 

Integer types are lower than floating point types

Signed types are lower than unsigned types

Short whole number types are lower than longer types

Answered by srishti3101
0

Answer:

Implicit Type Conversion Also known as 'automatic type conversion'.

Done by the compiler on its own. Generally takes place when in an expression more than one data type is present.  

All the data types of the variables are upgraded to the data type of the variable with largest data type.

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

unsigned int -> long -> unsigned ->  

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

Explicit Type Conversion Also known as 'type casting'.

Explicit type conversion or type casting is user defined type conversion. In explicit type conversion, the user converts one type of variable to another type.

Explanation:

Similar questions