Describe explicit conversion briefly



Explicit type conversion is a type conversion which is explicitly defined within a program (instead of being done by a compiler for implicit type conversion).
double da = 3.3;
double db = 3.3;
double dc = 3.4;
int result = (int)da + (int)db + (int)dc; //result == 9
//if implicit conversion would be used (as if result = da + db + dc), result would be equal to 10

There are several kinds of explicit conversion.
Checked:
Before the conversion is performed, a run-time check is done to see if the destination type can hold the source value. If not, an error condition is raised.
Unchecked:
No check is performed. If the destination type cannot hold the source value, the result is undefined.

Describe implicit conversion briefly.
provide coercion.

In a mixed-type expression, data of one or more subtypes can be converted to a super-type as needed at run-time so that the program will run correctly. For example, the following is legal C language code:
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 data types, they will be automatically converted to equal data types each time a comparison or assignment is executed.
Next Post Previous Post
No Comment
Add Comment
comment url