Preview
Explicit type conversion in C | Casting in C
It is the process of converting data type of the output of an arithmetic expression into a user specific data type as per his requirement. The syntax of casting is:
(Data_Type) Arithmetic_Expression
Data_Type is a valid data type of C language in which we want to convert the output of an expression.
Arithmetic_Expression is any valid arithmetic expression of C language.
Program |
#include<stdio.h> int main() { int a,b; float c; a=11; b=4; c=(float)a/b; /*Line 8*/ printf(“\nc=%f”,c); return(0); } |
Output |
c=2.75 |
Description |
In line 8 num1 and num2 are int type variables. so result of num1/num2 should be of int type but due to casting, result would be of float type. |
Best Books of Computer Science