Computer Science, asked by singhmedhansh036, 3 days ago

int a=5,b=10then find a+b+++--b+b
Increment Decreament
computer
Don't Spam
Spam Then Reported​

Answers

Answered by anindyaadhikari13
7

\textsf{\large{\underline{Solution}:}}

Given:

> a = 5

> b = 10

On evaluating the given expression:

= a + b++ + --b + b

= 5 + b++ + --b + b

= 5 + 10 + --b + b [b remains 10, post-increment]

= 15 + --b + b [Now b becomes 11]

= 15 + 10 + b [b becomes 10, pre-decrement]

= 25 + 10

= 35

★ So, the value of the expression is 35.

★ Also, the final values of a and b are 5 and 10 respectively.

\textsf{\large{\underline{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:

> int a = 2;

> int b = a++;

> b = 2

Now, a = 3.

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

Example:

> int a = 2;

> int b = ++a;

> b = 3

Also, a = 3


anindyaadhikari13: Thanks for the brainliest :)
Answered by kamalrajatjoshi94
1

Answer:

Given:-

int a=5,b=10;

To find:-

a+b++ + --b+b

Solution:-

=5+10+10+10

= 35

Steps:-

  • a is 5 only
  • b++ means initially the value doesn't change so it remains 10 here but the final value of 11 as it is post increment.
  • Now as the final value of b is 11 now it is pre-decremented so value is 10 and the final value of b is 10.
  • Now as b is 10 finally it's final value is 10.
  • Finally we add up and we get 35 as the answer.
Similar questions