+ 1

Why this is error in c++ int a=08; float b=09;int double c= 02; // this error not exit in c#

c++ code https://code.sololearn.com/cbRS6tdiAi6F/?ref=app C# code https://code.sololearn.com/crsf0brW7s4r/?ref=app

5th Aug 2018, 7:52 AM
Blacked False Positive
Blacked False Positive - avatar
10 Respuestas
+ 3
Blacked False Positive it's considered octal as it started with zero in c++... 8 is not available for octal and hence it shows error.. try with 07 and it will compile... I am not sure about c#... you might would like to refer below: https://www.geeksforgeeks.org/octal-numbers-c/
5th Aug 2018, 8:27 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 5
In C++, a number that is prefixed with a zero defines its base, which could either be: - binary (base 2) e.g. 0b00001000 (8) - octal (base 8) e.g. 010 (8) - hexadecimal (base 16) e.g. 0x8 (8) Valid digits allowed for a number expressed in base <n> is zero to <n> - 1. So in binary, 0,1 is valid (two digits), in octal, 0,1,2,3,4,5,6,7 is valid (eight digits), and in hexadecimal 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f is valid (16 digits). Your code tried to assign 08 which C++ assume as an octal number, but 8 isn't a valid digit to express an octal number, hence C++ tell you that through the error message (see the message by running the code). I don't know much about how C# treat zero prefixed numbers, but it seems that C# simply assume that 08 is just 8, perhaps C# has its own way to represent a number in a certain base, again, I'm not sure, a C# coder opinion is needed here : ) Hth, cmiiw
5th Aug 2018, 9:16 AM
Ipang
+ 3
c# has no notation for octal numbers iirc and therefore removes leading zeroes automatically
5th Aug 2018, 11:35 AM
hinanawi
hinanawi - avatar
+ 1
For c++ In visual studio input number less than 08 compiler give output but for 08,09 compiler give error and for 010 > number compiler consisder it octal number and give output in decimal number.For example for 0567 it give output 375 in decimal. oh thanks friend
5th Aug 2018, 9:02 AM
Blacked False Positive
Blacked False Positive - avatar
+ 1
Thanks guys I didn't know, about the octal base (I knew the hexa and binary)
5th Aug 2018, 9:25 AM
Comsis Alexis
Comsis Alexis - avatar
0
Maybe the error come from the 0 before the other number
5th Aug 2018, 7:54 AM
Comsis Alexis
Comsis Alexis - avatar
0
Maybe if you try to write a=8 b=9 and c=2
5th Aug 2018, 7:54 AM
Comsis Alexis
Comsis Alexis - avatar
0
Yeah this error bcu of zero but why in c++ not in c#
5th Aug 2018, 7:57 AM
Blacked False Positive
Blacked False Positive - avatar
0
Ah don't know why
5th Aug 2018, 7:57 AM
Comsis Alexis
Comsis Alexis - avatar
0
hey check out my profile and the code aaa has solved your problem and errrors
20th Aug 2018, 8:32 AM
Lol Hacker
Lol Hacker - avatar