6

This might be appear to be a silly/trivial question at first, but when I do this:

char f_gear = 15;

I get the normal output

"☼"

but when I pad it with zeros when i declare it:

char f_gear = 015;

I get weird output makes text look garbled (in one line) and blanks the previous line. When I attempt to see the individual character itself, I get the following:

"  ◘◘@╧S☻ "

What is essentially different? Isn't 15==015?

==EDIT== Stack Overflow changed the text when I posted the question. The output I really saw was a few blank characters.

ayane_m
  • 962
  • 2
  • 10
  • 26
  • Forgive me if it's a duplicate, I never knew numbers starting with 0 were octal. – ayane_m Feb 22 '13 at 05:08
  • No problem. You might find this interesting as well: http://stackoverflow.com/questions/6895522/is-0-a-decimal-literal-or-an-octal-literal – jogojapan Feb 22 '13 at 05:11
  • http://stackoverflow.com/questions/44569/octal-number-literals-when-why-ever – Josh Petitt Feb 22 '13 at 05:12
  • @jogojapan how did you put the text as hyperlink in your comment? I can do this in answers, but in comments this technique eludes me. – Josh Petitt Feb 22 '13 at 05:13
  • 2
    @JoshPetitt In the 'possible duplicate' case above it happened automatically, because that comment is inserted whenever somebody votes to close a question as duplicate. But in the general case you can use the same Markdown syntax as in regular posts: `[anchortext](href)`, for example `[link to google](https://www.google.com/)` will produce [link to google](https://www.google.com/). – jogojapan Feb 22 '13 at 05:19

5 Answers5

11

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

So,

char f_gear = 015;

is equivalent to

char f_gear = 13;
RAM
  • 2,413
  • 1
  • 21
  • 33
7

015 is octal notation. You can read about it here: http://en.wikipedia.org/wiki/Octal. It is not used much.

justinvf
  • 2,939
  • 2
  • 14
  • 9
3

All number literals that start with 0 are in octal.

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
1

Example, If We write the number "15". The compiler will recognize that as: 0000 1111 in binary.

If We write the number 015 the compiler will recognize that as octal and will see it as 0000 1101 in binary.

1

char f_gear=015 is considered octal,and hence it is equivalent to char f_gear=13. ASCII 13 is for carriage return ,which is the cause of the result. Snippet below shows the valuesenter image description here

Manuj
  • 253
  • 1
  • 7
  • 14