int d=6, p=10; p++; d+=d++ - ++p + d; what will be the value of p and d?
Answers
Answered by
3
- The final values of d and p are 7 and 12.
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.
There are two types of increment/decrement operations.
- Post increment/decrement.
- 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