What is Type Casting in C-language?
Type Casting means to change the variable into one data type to another data type. If the compiler will automatically change one data type to another data type. or you can forcefully change one data type to another data type.
Why need to Type Casting in Computer Language?
Every Computer language having type conversion or TYPE CASTING service available. It is used in computer programming to ensure variables are correctly processed by a function. An example of typecasting is converting an integer to a character. This might be done in order to compare two numbers when one number is saved as a character and the other is an integer
There are 2 types of Type Casting:-
1.) Implicit Type Casting:- In this type of typecasting we do convert the data type into one to another but also store that converted value in a variable of the corresponding data type. It handles by the compiler.Syntax
{
int a;
float b=10.34;
a=b; //Implicit type casting
}
2.)Explicit Type Casting:- In this type of typecasting we do convert the data type for a particular set of instructions. It is forcefull type cast by the programmer
Syntax
{
int a;
float b=10.34;
a=(int)b/2; //Explicit type casting Only for this instructions b act as Intger not float
}
We you have any doubt let me know :)