Search code examples
ctype-conversiondecimaloctal

Is 012e2 octal or float?


How should this be parsed in C language?

1000 

(if octal 012 * 10 ^ 2)

or

1200 

(if entire number as decimal)?


Solution

  • A constant with an exponent is always floating-point.

    There are no octal floating-point constants in C. (There are hexadecimal floating-point constants, but this isn't one of them).

    So 012e2 is an unnecessarily confusing way to write 1200.0.

    (I can think of no good reason to write it this way, unless the intent is to be deliberately confusing.)