The expression 4 + 8 % 2 gives the output
Answers
Answer:
i thought 2%8=4 ? because n%m gives reminder obtained by this ,correct me if i am wrong – John Feb 21 '11 at 6:22
1
No you are wrong as 2 is less then 8 so it is certainly not divisible (unless going into fraction which doesn't happen in Mod operation)and hence any thing less than 8 will get thrown as remainder like 7%8 = 7 but 9%8 = 1. Its a simple division operation you simply don't divide anything if number to be divided is less than number dividing it as it will be less than 1 – Shekhar_Pro Feb 21 '11 at 6:29
add a comment
Up vote13Down vote
x=4+2%-8; is equivalent to x = 4 + (2 % -8); which gives x = 4 + 2 which is 6.
More: C Operator Precedence Table
share improve this answer follow
answeredFeb 19 '11 at 13:02
user418748
editedJun 8 '12 at 12:25

Wladimir Palant
52.6k●1111 gold badges●9090 silver badges●120120 bronze badges
13
+1: But one gripe; the value of (x % y) for negative y is implementation-defined in C90. – Oliver Charlesworth Feb 19 '11 at 13:04
add a comment
Up vote3Down vote
Because the precedence of the operator % is the highest from the equation, the program first executes the operation 2 % 8 which is 2 and the adds this to 4.
Answer:
4
Explanation:
first 8%2
%means remainder which will become zero
and then 4 is added 4+0 =4 is Ans
as per Java this is process