Typecasting in C
Typecasting in C
What is Typecasting in C?
Definition:
Typecasting in C is the process of converting one data type into another manually.
Types of Typecasting in C
Types of Typecasting in C:
Implicit Typecasting
1. Implicit Typecasting:
- Happens when assigning a smaller type to a bigger type (e.g., int to float).
Example:
int a = 10;
float b = a;
Explicit Typecasting
2. Explicit Typecasting:
- Used to convert one data type into another using cast operator.
Typecasting in C
Syntax:
(data_type) expression
Example:
float a = 5.7;
int b = (int) a;
int a = 5, b = 2;
float result;
result = (float)a / b;