Computer Science, asked by helmsleybryanyu, 4 months ago

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 PranathP
4

\huge\mathfrak\orange{Hello..!!}

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