increment decrement expression evaluation – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2016-03I #JAVA#4254    siteicon   siteicon  

Problem Statement - increment decrement expression evaluation

Give the output of the following expression :
a+=a++ + ++a + -–a + a-– ; when a = 7

Solution

TC++ #4254

Doing it step by step:
a=7;
a+=a++ + ++a + -–a + a-– ;
the assignment will happen at last so we will do for RHS first

Step 1:   7 + 9 + 8 + 8    //Second number will increment twice one due to previous post increment and then due to current pre increment. Last post decrement will not have any effect.
Step 2: 32
Step 3: a+=32         //with a still as 7 as it was part of assignment
Step  4: a = 39        //final answer


Share

sunmitra| Created: 31-Mar-2018 | Updated: 16-Apr-2019|ICSE2016






Back