Search code examples
c++octal

what is the reason for the difference between setprecision (12) and setprecision (012) for example,in c++?


In c++ when you write setprecision (12) for example, 12 is in the base of 10 but when you write it like setprecision (012) it is an octal number,why?


Solution

  • Because constants with leading zeros (other than leading 0x) are always octal:

    An octal integer literal (base eight) begins with the digit 0 and consists of a sequence of octal digits.

    C++ draft standard (n1905) §2.13.1

    It has nothing at all to do with setprecision.