Question: #include using namespace std; int main() { int integer1, integer2; double result; integer1 = 19; integer2 = 2; result = integer1 / integer2; cout result
#include
using namespace std;
int main()
{
int integer1, integer2;
double result;
integer1 = 19;
integer2 = 2;
result = integer1 / integer2;
cout
result = static_cast
cout
result = static_cast
cout
return 0;
}
The question asks for the output of the code, I put 9 9.5 9 and it seems correct
But I don`t quite understand the type casting part.
For example, type of result is double, and type of integer1 = 19 & integer2 = 2 is int,
integer1 / integer2 = 9.5, since 9.5 is assigned to result and result is double, why can`t the first output be 9.5?
Same with the other two outputs, please provide a thorough explanation.
Thanks a lot
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
