问题
I've seen this char
defined as
char ch = '\117'
What kind of representation is '\117'
in?
I know escaped-sequence
is '\n'
, for instance, or unicode
is `\udddd'
, where d
is a single hex digit, but I've never seen such thing as '\117'
in my entire life!
Surprisingly, it does compile! (And the output is O
)
回答1:
This is the octal representation for ascii. You can see lots more values of it here: http://donsnotes.com/tech/charsets/ascii.html
回答2:
It's in octal, a holdover from C/C++.
回答3:
That is because its the Octal representation of captial O character.
If you try to print your char ch='\117';
, you will see that it prints O
.
回答4:
It's a Octal value for character "O", when I did system.out.println(..) I got this output:
char ch = '\117';
System.out.println("Char is: " + ch);
Output:
Char is : O
来源:https://stackoverflow.com/questions/14950593/why-is-117-a-valid-character-literal-in-java