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 will be the value of c after evaluating the given expressions on the left side for following two set of statements. Also justify your answer
(i) int j=5; int c=(5*++j)%6;
(ii) int j=5; int c=(5*j++)%6;
Solution
TC++ #5358
Run Output
0
1
(i) int j=5; int c=(5*++j)%6;
this will evaluate as follows
(5*6)%6 //prefix increment will make j as 6
(30)%6 //Modulus operator will calculate remainder of division 30/6
0 //Remainder will be 0
(ii) int j=5; int c=(5*j++)%6;
this will evaluate as follows
(5*5)%6 //postfix increment will not increment j in this instruction
(25)%6 //Modulus operator will calculate remainder of division 25/6
1 //Remainder will be 1
Common Errors
Student often confuse between prefix and postfix operators. Just remember that in prefix operator computation happens after incrementing and in postfix operator computation happens and then incrementing is done.