Below code gives output as 8. How it is possible? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Below code gives output as 8. How it is possible?

#include <iostream> using namespace std; int main() { int a=010; cout<<a; return 0; } // Output: 8

7th Oct 2017, 4:07 AM
Arjun gowda
Arjun gowda - avatar
3 Answers
+ 3
@Arjun Gowda The support for 0b was added only after C++03, so if you use an older compiler, 0b may just return an error.
7th Oct 2017, 4:27 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
0
what about this? #include <iostream> using namespace std; int main() { int a=0b111; cout<<a; return 0; } //Output 7
7th Oct 2017, 4:18 AM
Arjun gowda
Arjun gowda - avatar
0
ok what is the prefix for hexadecimal?
7th Oct 2017, 4:23 AM
Arjun gowda
Arjun gowda - avatar