+ 5

Why this code will cause an error

#include<iostream> using namespace std; int main() { int a=09; cout<<a; } https://code.sololearn.com/cI4FL3C0Hvv4/?ref=app

16th Sep 2020, 4:38 PM
kishor pawar
kishor pawar - avatar
4 Réponses
+ 5
Because 09 is an invalid octal number, When add zero in front of a number the compiler looks that number as an octal number, And an octal number ranges between 0-7 digits
16th Sep 2020, 4:52 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 3
16th Sep 2020, 5:01 PM
kishor pawar
kishor pawar - avatar
+ 3
I change 012 to 0123 and now it is giving output 83? Because, it's taken as octal base (8), since that numeral have 0 in leading. So, it's corresponding decimal value is 10. 012 : (2 * 8 ^ 0) + (1 * 8 ^ 1) = 10 0123 : (3 * 8 ^ 0) + (2 * 8 ^ 1) + (1 * 8 ^ 2) = 83
16th Sep 2020, 6:01 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Now i understand that 0 is for octal
16th Sep 2020, 6:15 PM
kishor pawar
kishor pawar - avatar