0

Output of 3/4*4

If I write cout<<3/4*4 the output is 0. Shouldn't the output be 3 as / and * have same precedence so code is evaluated left to right so (3/4)*4 =1.

2nd Apr 2020, 9:30 AM
Ram Keswani
Ram Keswani - avatar
1 Respuesta
+ 4
Integer division does not preserve the decimal point (if any) of an operation result. You probably meant 3 instead of 1. 3 /4 -> 0.75 0.75 * 4 -> 3
2nd Apr 2020, 9:44 AM
Ipang