Expression evaluation based on precedence – Computer Sir Ki Class

Login


Lost your password?

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

Login
[lwa]



Exam Questions-ICSE2015-03J #JAVA#4281    siteicon   siteicon  

Problem Statement - Expression evaluation based on precedence

If int y = 10 then find int z = (++y * (y++ + 5));

Solution

TC++ #4281

If int y = 10 then find int z = (++y * (y++ + 5));

Let us try to solve step by step based on precedence
Step1: starting with y=10
(++y * (y++ + 5))
11 * (11 + 5)   //First y will immediately increment as it is preincrement, next will not as it is post increment
Step 2:
11 * (16)
Step 3:
176
So z = 176


Share

sunmitra| Created: 6-Apr-2018 | Updated: 16-Apr-2019|ICSE2015






Back