Home >Backend Development >C++ >How Are Zero-Prefixed Numbers Interpreted in C ?
When dealing with integer literals in C , certain behaviors arise when the number starts with zero. These behaviors revolve around the base of the interpreted number.
When an integer literal begins with zero, it is typically interpreted as an octal number, also known as base-8. This means the digits used are from 0 to 7. For instance, 07 is equivalent to the decimal value 7.
However, when an integer literal is 00x, it is treated as a hexadecimal number, which uses base-16. It starts with the prefix 0x and employs digits 0-9 and A-F to represent decimal values 0-15.
An error occurs when an integer literal starts with 08 because this combination is undefined in C . There is no such thing as an octal digit 8.
If an integer literal starts with multiple zeros, all leading zeros except the first one are ignored. For example, 00016 is interpreted as the octal number 16, which equates to the decimal value 14. This is because 016 represents 14 in octal.
Therefore, in your given examples:
The above is the detailed content of How Are Zero-Prefixed Numbers Interpreted in C ?. For more information, please follow other related articles on the PHP Chinese website!