devxlogo

Octal Numerals

Octal Numerals

A literal integer preceded by 0 (zero) is an octal numeral. When using octal numbers, you should beware of the following common pitfall:

 const int warning = 10;const int error = 100, switch (status) {case 010   // OOPS, decimal value is 8, not 10   handle_warning ();  // unreachable code!   break;case 100:   handle_error ();   break;default:   break;}

In this example, the programmer intended to format the case-labels in a uniform, fixed size of thee digits. However, the compiler treated each zero-preceded label as an octal number rather than a decimal one.

See also  Is Machine Learning Automating Creativity in Graphic Design?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist