Home  >  Article  >  Backend Development  >  When you add 0 before a numeric constant in C/C++, it means it is an octal number

When you add 0 before a numeric constant in C/C++, it means it is an octal number

WBOY
WBOYforward
2023-09-01 17:41:061358browse

When you add 0 before a numeric constant in C/C++, it means it is an octal number

Sometimes we may see some numeric literals with a 0 prefix. This indicates that the number is octal. So octal literals contain 0 at the beginning. For example, if the octal number is 25, then we must write 025.

Example

#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

The above is the detailed content of When you add 0 before a numeric constant in C/C++, it means it is an octal number. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete

Related articles

See more