I'm not a C++ developer, but today I've found a C++ code and try to understand it. So I've stacked on this piece of code:
int m = 2, n = 3, i = 1;
double mid = (double)m / n * i;
int d = (int)mid + 1;
printf("%d %d\n", mid, d);
The result which is going to be printed to the console is: 1431655765 1071994197. It seems to be related with the casting of variable m to double, but I have no idea how it is happening. I need someone to help me understand it. Thanks in advance!
You should print a double(mid
) with the %lf
format specifier in printf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With