What is the difference between 15 and 015 years?

This may seem like a dumb / trivial question at first, but when I do this:

char f_gear = 15; 

I get a normal output

 "☼" 

but when I declare it zeros, when I declare it:

 char f_gear = 015; 

I get a weird output that makes the text look distorted (in one line) and runs through the previous line. When I try to see a single character, I get the following:

 "  ā—˜ā—˜@ā•§S☻ " 

What is significantly different? Not 15 == 015?

== EDIT == Stack overflow changed the text when I posted the question. The result that I really saw was a few empty characters.

+6
source share
5 answers

No, 015 refers to the octal number. So 015 in octal is 13 in decimal.

So,

 char f_gear = 015; 

equivalently

 char f_gear = 13; 
+11
source

015 - octal notation. You can read about it here: http://en.wikipedia.org/wiki/Octal . It is of little use.

+7
source

All number literals starting with 0 are in octal format.

+3
source

Example, if we write the number "15". The compiler recognizes this as: 0000 1111 in binary format.

If we write the number 015, the compiler will recognize this as octal and see it as 0000 1101 in binary format.

+1
source

char f_gear = 015 is considered octal, and therefore it is equivalent to char f_gear = 13. ASCII 13 is designed to return a carriage, which is the reason for the result. Below picture shows the values enter image description here

+1
source

All Articles