User Forum

Subject :NCO    Class : Class 9

What would be the value of variable res after execution?
res = 9 Mod 2 + 1 - 2
A -1
B 3
C 0
D 4


Answer is (C)

Ans 1:

Class : Class 8
The solution says the answer is C

Ans 2:

Class : Class 9
Assuming that the language used is java. So there is something called precedence of operators. unary + and unary - have a precedence of 13 while Modulus (Mod) has a precedence of 12 which is lower than that of + and -. this is how the calculation takes place : res = 9 Mod 2 + 1 - 2; res = 9 Mod 3 - 2; res = 9 Mod 1; res = 0; (Remainder of 9 / 1 = 0) Hope you understand. Best of luck for your Exams! : )

Post Your Answer