Write the shortest way to express each of the following statements.
A. x = x - 1;
B. x = x / 2;
C. x = x + y;
D. x = 2*x;
Answers
Answered by
4
Answer:
Shortcuts for the above Assignment operators -
A. x-=1;
B. x/=2;
C. x+=y;
D. x*=2;
Additional:
- The following code compiles without error:
x = 3;
x += 4.6;
and results in x having the value 7.6 because it is equivalent to:
x = 3;
x = (x + 4.6);
- x = x - 1 can also be written by using shortcut decrement arithmetic operator: x--
Similar questions
Hindi,
2 months ago
Science,
4 months ago
French,
4 months ago
Social Sciences,
9 months ago
Physics,
9 months ago