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(integer1) / integer2;

cout

result = static_cast(integer1 / integer2);

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!