c++ - What is special about numbers starting with zero? -
this kinda stupid question, it's interesting me )
this visual studio 2013
int = 07; // == 7 int = 16; // == 16 int = 00016; // == 14, why? int = 05016; // == 2574, wow ) int = 08; // compile error, compiler expects octal number...
if number starts 0 , contains 8, it's compile error. normal? , compiler starting zeros if 00016 == 14?
thanks ))
yes, expected.
[c++11: 2.14.2/1]:
integer literal sequence of digits has no period or exponent part. integer literal may have prefix specifies base of operations , suffix specifies type. lexically first digit of sequence of digits significant. decimal integer literal (base ten) begins digit other 0 , consists of sequence of decimal digits. an octal integer literal (base eight) begins digit 0 , consists of sequence of octal digits.22 hexadecimal integer literal (base sixteen) begins 0x or 0x , consists of sequence of hexadecimal digits, include decimal digits , letters through f , through f decimal values 10 through fifteen. [ example: number twelve can written 12, 014, or 0xc. —end illustration ]
22 the digits 8 , 9 not octal digits.
c++ c syntax compiler-construction numbers
No comments:
Post a Comment