2. TYPE CASTING
▪ Type Casting is the process in which the compiler
automatically converts one data type in a program to
another one.
▪ Type conversion is the another name for type casting.
▪ There are two types of type casting they are ...
▪ ImplicitType Casting
▪ ExplicitTupe Casting
3. IMPLICIT TYPE CASTING
▪ ImplicitType Conversion Also known
as ‘Automatic type conversion’.
▪ Done by the compiler on its own, without any
external trigger from the user.
▪ Generally takes place when in an expression more
than one data type is present. In such condition
type conversion takes place to avoid lose of data.
▪ All the data types of the variables are upgraded to
the data type of the variable with largest data type.
4. IMPLICIT TYPE CASTING
▪ EXAMPLE
▪ #include<stdio.h>
▪ void main()
▪ {
▪ int k=54;
▪ float s;
▪ s=k;
▪ printf("Implicit value is %f",s);
▪ }
OUTPUT:
Implicit value is 54.0000
5. EXPLICIT TYPE CASTING
▪ In explicit type conversion user manually converts one data
type into another type therefore it is known
as 'user-defined'.
▪ The user can define the type to which the expression is to
be converted , it can be larger or smaller data type.
▪ Explicit type conversion can be achieved by using cast
operator.
6. EXPLICIT TYPE CASTING
▪ EXAMPLE
#include<stdio.h>
void main()
{
int k=54;
float s;
s=(float)k;
printf("Explicit value is %f",s);
}
▪ OUTPUT :
▪ Explicit value is 54.0000
7. ADVANTAGES OF TYPE CASTING
• Type casting helps a programmer convert any given
data type to any other data type in a program.
• It makes any given program very lightweight.
• Using type casting, one can take advantage of several
features, such as arithmetic conversion hierarchy and
type representations.