Computer Science, asked by anjalimishra5449, 1 month ago

int a=11 ; b =22 , c;
c= a + b + a++ + b++ + ++a + ++b
System. out. println ( a+b+c+34)​

Answers

Answered by anindyaadhikari13
8

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

  • The output of the given co‎de is 174.

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

Given:

> a = 11

> b = 22

On evaluating the value of c:

> c = a + b + a++ + b++ + ++a + ++b

> c = 11 + 22 + a++ + b++ + ++a + ++b [Substitute the values of a and b]

> c = 33 + 11 + b++ + ++a + ++b [a remains 11, post-increment]

> c = 44 + b++ + ++a + ++b [a becomes 12]

> c = 44 + 22 + ++a + ++b [b remains 22, post-increment]

> c = 66 + ++a + ++b [b becomes 23]

> c = 66 + 13 + ++b [a becomes 13, pre-increment]

> c = 79 + ++b

> c = 79 + 24 [b becomes 24, pre-increment]

> c = 103

Therefore:

 \implies\begin{cases} \sf a = 13 \\  \sf b = 24 \\  \sf c = 103 \end{cases}

Now, the value of a + b + c + 34 will be,

= 13 + 24 + 103 + 34

= 37 + 34 + 103

= 71 + 103

= 174

So, the output of the given co‎de is 174.

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