+ 27

Must know for every programmer. Check you may or may not know this.

In Java,C/C++, Perl, PHP, Javascript, Ruby, Python ... int x = 010; This assigns x to have the value 8. Any integer preceded with a zero in these languages is presumed octal.

27th Feb 2017, 5:11 PM
Ram chandra Giri
Ram chandra Giri - avatar
6 Answers
+ 4
@Raj Kumar Chauhan: Seems showing toking error in Python 3.x, but is 8 in Python 2.x ^^
28th Feb 2017, 3:14 PM
visph
visph - avatar
+ 2
x=010 print (x) shows token error in python
27th Feb 2017, 5:51 PM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
+ 2
in python Capital O in front of the number generates defines octal. 0(zero) causes token error.
7th Mar 2017, 4:47 PM
Alan Beveridge
Alan Beveridge - avatar
+ 1
朘朔拉
27th Feb 2017, 5:25 PM
朘朔拉
朘朔拉 - avatar
+ 1
In java int x=012 //output is 10 converted to octal
6th Mar 2017, 6:05 PM
Gautham Raj S
Gautham Raj S - avatar
0
So basically Int x = 017; x would be 16.
27th Feb 2017, 5:44 PM
NickB
NickB - avatar