Computer Science, asked by SuryaDevil1290, 7 days ago

int d=6, p=10; p++; d+=d++ - ++p + d; what will be the value of p and d?​

Answers

Answered by anindyaadhikari13
3

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

  • The final values of d and p are 7 and 12.

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

Given:

> d = 6

> p = 10

> p++ [Value of p is incremented]

> p = 11 [p becomes 11]

> d+=d++ - ++p + d

> d = d + d++ - ++p + d

> d = 6 + 6 - ++p + d [d remains 6, post-increment]

> d = 12 - ++p + d [d becomes 7]

> d = 12 - 12 + d [p becomes 12, pre-increment]

> d = 0 + d

> d = 0 + 7

> d = 7

★ So, the final values of d and p are 7 and 12.

\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


anindyaadhikari13: Thanks for the brainliest ^_^
Similar questions