Type Conversions IN C++: by Prof - Manikandan QMC College, Medavakkam
Type Conversions IN C++: by Prof - Manikandan QMC College, Medavakkam
IN C++
By
Prof.Manikandan
TYPE CONVERSIONS
The compiler
does not support automatic type
conversions for the user defined data types.
We can use casting operators functions to do this.
int a=31;
int b=3;
float y=staitc_cast <float>(a)/b;
Out put:
10.3333
EXAMPLE PROGRAM
#include<iostream.h>
int main()
{
int a=31;
int b=3;
float x=a/b;
float y=static_cast<float> (a)/b;
cout<<"output without static_cast ="<<x;
cout<<"output with static_cast ="<<y;
return 0;
}
Output:
output without static_cast =10
output with static_cast =10.3333
1.
2.
3.