Computer Science, asked by khantahmin1, 2 months ago

If var x=5, var y=9, Calculate the value of x x = x++++y + x;​

Answers

Answered by anindyaadhikari13
3

ANSWER.

  • The value of x is 21.
  • The value of y is 10.

EXPLANATION.

Given –

> var x = 5

> var y = 9

> x = x++ + ++y + x

> x = 5 + ++y + x (Value of x is not changed, post-increment)

> x = 5 + ++y + x (x becomes 6)

> x = 5 + 10 + x (y becomes 10, pre-increment)

> x = 15 + 6 (substitute the value of x here)

> x = 21

> y = 10

★ So, the values of x and y are 21 and 10 respectively.

LEARN MORE.

There are two types of increment/decrement operations.

  1. Post increment/decrement.
  2. Pre increment/decrement.

Post Increment/Decrement – Here, operation takes place first and then the value is incremented/decremented.

Example –

> var a = 2;

> var b = a++;

> b = 2

Now, a = 3.

Here, initialisation takes place first and then value is incremented.

Pre Increment/Decrement – Here, value is first increment/decrement and then the operation is carried out.

Example –

> var a = 2;

> var b = ++a;

> b = 3

Also, a = 3

Similar questions