Output will be:
enter a:3
enter b:12
Reason:
First evaluate the values of prefix operations and then solve the problem by using using that value.
Here,
a=3
b=++a + a++ + a-- + --a
so, a=3+1-1=3 (1 prefix increment and 1 prefix decrement)
hence, b=3+3+3+3=12
a=3+1+1-1-1=3
User Profile
Collapse
-
The simplest trick is to calculate the prefix operators first and then put the net value in the expression.
1. i++ + i++
No prefix operator. so, i=5
exp=5+5=10, i=5+1+1=7
2. i-- - i++
No prefix operator. so, i=5
exp=5-5=0, i=5-1+1=5
3. ++i - --i
net value of i= 5+1-1=5
exp=5-5=0, i=5+1-1=5
4. --i + i--
net value of i= 5-1=4
exp=4+4=8, i=5-1-1=3Leave a comment:
No activity results to display
Show More
Leave a comment: