Computer Science, asked by km8385146, 1 month ago

int c=6; c+ = ++c * c-- / ++c % c--;


solve increment and decrement java​

Answers

Answered by anindyaadhikari13
3

\texttt{\textsf{\large{\underline{Answer}:}}}

  • The final value of c is 6.

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

Given:

> c = 6

> c += ++c * c-- / ++c % c--

> c += 7 * c-- / ++c % c-- (c becomes 7, pre-increment)

> c += 7 * 7 / ++c % c-- (c remains 7, post-increment)

> c += 7 * 7 / ++c % c-- (c becomes 6)

> c += 7 * 7 / 7 % c-- (c becomes 7, pre-increment)

> c += 7 * 1 % 7 (c remains 7, post-increment)

> c += 7 % 7

> c += 0

> c = 6 + 0

> c = 6

★ So, the final value of c is 6.

\texttt{\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

Similar questions