What is 0 (zero) - A decimal literal or An octal literal in C++

C++Server Side ProgrammingProgramming

The 0 (Zero) before a number is basically the octal literal.

In C/C++ we can use octal literals by typing a zero before the actual number. For example, if an octal number is 25, then we have to write 025.

Example Code

#include <stdio.h>
int main() {
   int a = 025;
   int b = 063;
   printf("Decimal of 25(Octal) is %d\n", a);
   printf("Decimal of 63(Octal) is %d\n", b);
}

Output

Decimal of 25(Octal) is 21
Decimal of 63(Octal) is 51
raja
Published on 09-Apr-2019 09:03:07
Advertisements