Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using visual studio 2017,so is it because of that it gives me an error "invalid octal digit"?

What I have tried:

if i give a integer variable value that starts with 0 then only this error comes something like this int e = 0129612;
but it doesn't gives any error if i just don't use 0 on the first place.
Posted
Updated 19-Jul-18 7:05am
Comments
KarstenK 19-Jul-18 4:56am    
The language convention of C++ is saying that start with a "0" is an octet number. Compare to "0x" which is hexadecimal. :-O

Octal digits can range from 0 to 7. This is because octal is base 8. A literal integer value starting with 0 is considered to be octal. If it starts with 0x it is a hexadecimal value.
 
Share this answer
 
v2
C/C++ knows three types of integer literals: octal, decimal, and hex.
Since C++14 there is a fourth type: binary.

A literal beginning with a zero and followed by another digit is treated as octal value (base 8) which is not allowed to contain the digits 8 and 9.

See also integer literal - cppreference.com[^].
 
Share this answer
 
Quote:
if i give a integer variable value that starts with 0 then only this error comes something like this int e = 0129612;
but it doesn't gives any error if i just don't use 0 on the first place.

Because it is the principle: integers starting with 0 are octal (base 8)
 
Share this answer
 
thank you everyone for responding it is of great help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900