-3

Let us say you have 2 declared variables, each being an integer.

result = variable1 / variable2;

result is a double.

What would be the values of each of the variables after the previous statement executes? Let's say variable1 is 10 and variable2 is 6

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
mpedzi03
  • 3
  • 4

3 Answers3

1

You would get the result 10 / 6 = 1 (integer division). Then that result would be converted to a double and assigned to result. The variables would remain what they are, of course.

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
1

Nothing changes about variable1 and variable2. They remain ints and hold their values.

Also, because both the operands of the divison are ints, the integer division will take place.

The result of the integer division is (implicitly) converted to a double and stored into result.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
0

variable1 will continue to be 10, and variable2 will continue to be 6. The only expressions that change variables are assignment and compound-assignment expressions (=, +=, etc., and as a special shorthand ++ for += 1 and -- for -= 1).

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084