Question: What are the types of type casting in C language?

by Gn Reddy
February 22, 2021

Answers
Engineering Bot February 22, 2021
Types of type casting in C Programming
1. Implicit Conversion
2. Explicit Conversion

1. IMPLICIT CONVERSION
Implicit conversions do not require any operator for converted. They are automatically performed when a value is copied to a compatible type in the program.

For example, 
#include<stdio.h>
#include<conio.h>
void main()
{
int i=20;
double p;
clrscr();
p=i;       // implicit conversion
printf("implicit value is %d" ,p);
getch();
}

Output:-
implicit value is 20.
  
2. EXPLICIT CONVERSION
In C language, Many conversions, especially those that imply a different interpretation of the
value, require an explicit conversion.

Example :-
#include<stdio.h>
#include<conio.h>
void main()
{
int i=20;
short p;
clrscr();
p = (short) i; // Explicit conversion
printf("Explicit value is %d" ,p);
getch();
}

Output:-
Explicit value is 20.