Type Conversion in C Language

 

Type conversion in C language

Type conversion in C language refers to the process of converting a value of one data type into another data type. There are two types of type conversion: implicit and explicit.

    Implicit Type Conversion:

Implicit type conversion is also known as automatic type conversion. It occurs when the compiler automatically converts one data type into another data type without any explicit instruction from the programmer. Implicit type conversion occurs when:

A value of a smaller data type is assigned to a variable of a larger data type.

A value of a lower-ranked data type in the type hierarchy is assigned to a variable of a higher-ranked data type.

For example:

int a=10;

float b=a; // Implicit Conversion

In the above example, the integer value 10 is automatically converted to a floating-point value and assigned to the variable b.

 Explicit Type Conversion:

Explicit type conversion is also known as type casting. It occurs when the programmer explicitly instructs the compiler to convert a value of one data type into another data type.

Explicit type conversion is done using the cast operator, which is represented by parentheses ().

For example:

float b=10.5;

int a = (int)

In the above example, the floating-point value 10.5 is explicitly converted to an integer value using the cast operator and assigned to the variable a.

Note that explicit type conversion can result in data loss if the value being converted cannot be represented by the target data type. It is the responsibility of the programmer to ensure that the data being converted is within the range of the target data type.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
About
Products
Subscribe

If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

    Applauz

    As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

    Subscribe

    If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

      Applauz

      As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

      Copyright by BOLD THEMES. All rights reserved.