C++, How 3 (Help) I tried but I don't know how 3%5 output comes 3 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++, How 3 (Help) I tried but I don't know how 3%5 output comes 3

Int a=3; Int b=a++; Cout<<b%++a

27th Jun 2021, 10:44 AM
Nitin Bisht
Nitin Bisht - avatar
5 Answers
+ 5
When LHS is less than RHS then LHS is returned. In C++ modulo operator only works with integral operands, and since 3 % 5 doesn't even make 1 quotient, 3 was returned.
27th Jun 2021, 10:53 AM
Ipang
+ 2
If you try to divide 3 by 5 , you will get 3 as remainder and quotient will be 0.
27th Jun 2021, 10:52 AM
Abhay
Abhay - avatar
+ 2
Ipang well explained answer
27th Jun 2021, 10:59 AM
Nitin Bisht
Nitin Bisht - avatar
+ 2
Nitin Bisht % don't divide fully but rather stop at a less value or at a integer and then returns the extra value . I should have included in my previous answer that i was talking in context of "%" not "/"
27th Jun 2021, 11:21 AM
Abhay
Abhay - avatar
+ 1
Abhay if I am trying to divide 3 by 5 , I will get 0 as remainder and quotient will be 0.6
27th Jun 2021, 11:02 AM
Nitin Bisht
Nitin Bisht - avatar