Type conversion Implicit and Explicit in c
BM Balmiki Mandal 12 Aug 2022 14 views 0 comments C Programming

Type conversion Implicit and Explicit in c

Type conversion / type Promotion in c 

When the constant and different variable in between the same operator is There then they all are converted into the same operand. The compiler converts all operands up to the type of biggest Operand 

Example

char ch;
int I, Result;
float f;
double d;

Result=  ( ch/i +  f*d  -  f-i )

Conclusion: here char is converted into int and float is converted into double. so any primitive type of data converted into another primitive type of data is called type Type promotion or type conversion.

Implicit conversion is done by the compiler and Explicit conversion is user-defined conversion.

There are two of type conversion

  1. implicit type conversion
  2. Explicit type conversion

Implicit Type conversion

Implicit Type conversion bone by the compiler we no need to do any anything. it also in two types 

  1. Automatic Type conversion
  2. Type conversion in assignment

 Automatic type conversion also two types

  1. Automatic unary conversion
  2. Automatic binary conversion

Automatic type conversion also has two types

Automatic unary Type conversion (integral promotion): all character and short integer values are automatically converted into integers is called integral or unary promotion 

Automatic Binary conversion: if one operand is a long double other will be converted into a long double 

Type conversion in assignment

  • in Expression, if data types or operand are different then Right-hand side data is converted into left-hand side data of the operand.
  • if the right-hand side operand is lowest than the left-hand side operand then the right hand side operand is promoted.
  • if the right-hand side operand is higher than the left-hand side operand then right-hand side operand is promoted
  • some higher order bits are dropped when long is converted into int or int is converted into short int or char
  • the fractional part is truncated during the conversion of float to int 
  • when double is converted into float then digits are round off
  • when the signed type is changed to an unsigned type then sign may be dropped
  • when int is converted into float or float is converted into double ther will be no increase in accuracy or presion 

Explicit type conversion(type casting):

Type conversion / type Promotion:

When the constant and different variable in between the same operator is There then they all are converted into the same operand. The compiler converts all operands up to the type of biggest Operand 

Example

char ch;
int I, Result;
float f;
double d;

Result=  ( ch/i +  f*d  -  f-i )

Conclusion: here char is converted into int and float is converted into double. so any primitive type of data converted into another primitive type of data is called type Type promotion or type conversion.

Implicit conversion is done by the compiler and Explicit conversion is user-defined conversion.

There are two of type conversion

  1. implicit type conversion
  2. Explicit type conversion

Implicit Type conversion

Implicit Type conversion bone by the compiler we no need to do any anything. it also in two types 

  1. Automatic Type conversion
  2. Type conversion in assignment

 Automatic type conversion also two types

  1. Automatic unary conversion
  2. Automatic binary conversion

Automatic type conversion also has two types

Automatic unary Type conversion (integral promotion): all character and short integer values are automatically converted into integers is called integral or unary promotion 

Automatic Binary conversion: if one operand is a long double other will be converted into a long double 

Type conversion in assignment

  • in Expression, if data types or operand are different then Right-hand side data is converted into left-hand side data of the operand.
  • if the right-hand side operand is lowest than the left-hand side operand then the right hand side operand is promoted.
  • if the right-hand side operand is higher than the left-hand side operand then right-hand side operand is promoted
  • some higher order bits are dropped when long is converted into int or int is converted into short int or char
  • the fractional part is truncated during the conversion of float to int 
  • when double is converted into float then digits are round off
  • when the signed type is changed to an unsigned type then sign may be dropped
  • when int is converted into float or float is converted into double ther will be no increase in accuracy or presion 

 

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

C Bitwise Operators Explained: 10 Practice Programs with Output

E.1: Bitwise vs. Logical Operators#include<stdio.h> int main(void){ int x=7,y=19; printf("%d %d ",x&y...

AG Anvesh G 29 Nov 2026
Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026