Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
What is the value of y after evaluating the expression given below?
y+=++y + y– + –y; when int y=8
Answer:
If int y = 8 we will put the value in expression and evaluate
y += ++y + y– + –y;
+= being the composite assignment, will be evaluated in the end so step 1 would to evaluate RHS
Step 1: RHS-> 9 + 9 + 7; //First y will pre-increment, second will remain 9, third will decrement twice
Step 2: y = y+25; //Composite operator expanded, original y will remain as it is while expanding. This is because y will be filled first but due to last precedence of assignment it will not be impacted.
Step 3: y = 8+25 ; //Original value of y will be used here
So final y = 33
C. Sir| Created: 25-Mar-2018 | Updated: 12-Apr-2019|ICSE2018