QUESTION IMAGE
Question
int a = 3 / 4; double b = (double) 3 / 4; double c = 3.0 / 4.0; which of the following statements is true? a = 0 b = 0 c = 0
Step1: Analyze variable a
In C - like languages, when dividing two integers (3 and 4), integer division is performed. Integer division truncates the result towards zero. So, $3/4 = 0$ since it discards the fractional part.
Step2: Analyze variable b
When casting one of the operands to double ((double)3), floating - point division is performed. So, $b=\frac{(double)3}{4}= 0.75$.
Step3: Analyze variable c
When both operands are doubles (3.0 and 4.0), floating - point division is performed. So, $c = \frac{3.0}{4.0}=0.75$.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
a = 0