Skip to content
Advertisement

Why int j = 012 giving output 10?

In my actual project It happened accidentally here is my modified small program.

I can’t figure out why it is giving output 10?

JavaScript

After that, I put two zeros still giving output 10.

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

Can anyone explain why?

Advertisement

Answer

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 :

JavaScript

0123 :

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement