Why does:
int test() {
return 00101 % 10;
}
return 5
, while:
int test() {
return 101 % 10;
}
returns 1
? I can't think of an explanation.
Why does:
int test() {
return 00101 % 10;
}
return 5
, while:
int test() {
return 101 % 10;
}
returns 1
? I can't think of an explanation.
Integer literals beginning with 0
like
00101
is actually an octal constant.
00101 is in octal which is equal to 65 in decimal, so that is why the modulus operator will always give us 5. You can do octal to decimal converstion on this link http://www.rapidtables.com/convert/number/octal-to-decimal.htm