Answer to Question #236335 in C++ for Abdul

Question #236335
with good examples explain how integer data types can be type- cast into real numeric data types and vice versa
1
Expert's answer
2021-09-12T14:23:18-0400

In this case, I am explaining explicit type casting which allows the programmer to convert or typecasts datatype from int to float as well as from float to int.

float to int typecasting means that we are converting data of type float to int as illustrated by the following program;


#include <iostream>  
using namespace std;  
int main ()  
{  
float a = 5.4;  

int x = static_cast <int> (a);  
cout << " value of x = : " << x;  
return 0;  
}   



int to float typecasting means that we are converting data of type int to float as illustrated by the following program;


#include <iostream>  
using namespace std;  
int main ()  
{  
float a;  
int b = 10;    
a = (float) b;  
cout << "value of integer datatype: "<<b<<"\n";  
cout << " The value of float datatype a  : "<< a <<"\n";  
return 0;  
}  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS