Computer Science, asked by gokulavaasan42004, 4 months ago

Give the output of the following expression (2)

a += a++ + ++a + --a + a-- ; when a = 7.​

Answers

Answered by BrainlyProgrammer
3

Answer:

Given, a=7.

a+=a++ + ++a + --a + a--;

>>>a=a+(a++ + ++a + --a + a--);

>>>a= 7+(7+9+8+8) //now a's value is 7

>>>a=7+32

>>>a=39.

Note:-

  • In this question there is postfix(a++ or a--) and prefix(++a or --a) increment
  • Postfix increment means first calculate then increase the value.

  • that's why in the above solution a remains 7 even after a++ but as soon as it reaches ++a, a becoms 8
  • Prefix increment is just opposite of postfix increment, it means first increase then calculate.

  • given in above solution, when control reaches ++a, the current value of a is 8. As said, prefix means first increase then calculate, the value of a first increases to 9 , then the control moves further.

Hence, on calculating the final value of a is 39.

Answered by Oreki
2

After Execution:

a = 39

Explanation:

> a += a++ + ++a + --a + a--, a = 7,

> a += 7 + 9 + 8 + 8

> a += 16 + 16

> a = 7 + 32

> a = 39

Similar questions