Why int j = 012 giving output 10?

Than I change 012 to 0123 and now it is giving output 83?

Because, it’s taken as octal base (8), since that numeral have 0 in leading. So, it’s corresponding decimal value is 10.

012 :

(2 * 8 ^ 0) + (1 * 8 ^ 1) = 10

0123 :

(3 * 8 ^ 0) + (2 * 8 ^ 1) + (1 * 8 ^ 2) = 83

Leave a Comment