Computer Science, asked by patelamit132yahoocom, 22 days ago

evaluate c++a-b++ where a=6,b=2​

Answers

Answered by noobg3092
0

Answer:

Starting with a basic of pre increment and post increment.

++a means first the value is incremented and then it is used.

a++ means first the value is used then it is incremented.

So , we will solve this in steps.

Given: a=6

Step 1: b = (++a) + (a++) + (a++)

We know that precedence of parenthesis is higher than other operators. So we will solve parenthesis one-by-one.

1) ++a = 7 (it is a pre-increment) so (6+1=7) will be assigned to a.

2) a++ = 7 (it is post increment) it will remain same here.

Now, the value of a is incremented, it is 8 and it is assigned to a=8

3) a++ = 8 (it is post increment) so now value of a will be same.

Now, the value of a is incremented, it is 8 and it is assigned to a=9

Step 2: Now add all the value obtained in above steps and assign it to b

b = 7+7+8 = 22.

Step 4 After doing step 1, at last we got the value of a as 9.

so,a = 9, b = 22

Similar questions