What is type conversion? Discuss type casting with suitable example.

This answer is restricted. Please login to view the answer of this question.

Login Now

Type conversion is converting one type of data type to another type. It is also known as Type casting. Type conversion in C can be classified as

  1. Implicit Type Conversion
  2. Explicit Type Conversion

1. Implicit Type Conversion

When the type conversion is performed automatically by the compiler without programmer’s intervention, such type of conversion is known as implicit type conversion or type promotion.

int x;
for(x = 97; x <= 122; x++){
   
    //Implicit casting from int to char
    printf("%c", x);

}

b. Explicit Type Conversion

Th type conversion performed by the programmer by using posing the data type of the expression of the specific type is known as explicit type conversion. The explicit type conversion is also knowns type casting. Type casting in c is done in following form:

(data_type) expression;

Where, data_type is any valid C data type and expression may be constant, variable or expression.

For Example

int x = 7, y = 5;
float z;
z = (float) x / (float) y;

 

If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .