What the output of this question? bool y=5; cout<<y/2<<endl; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What the output of this question? bool y=5; cout<<y/2<<endl;

All the numbers in the language c++, shall be true except zero is false

13th Mar 2017, 4:25 AM
Nour Alnaser
Nour Alnaser - avatar
5 Answers
+ 10
don't have a compiler to test it but I guess it will output 0. bool y=5; => y=true; cout << y/2 ( true / 2 = 1 / 2 = 0 ) << endl;
13th Mar 2017, 5:50 AM
Nikolay Nachev
Nikolay Nachev - avatar
+ 2
yes the output is 0 ... thank you 🙂
13th Mar 2017, 7:10 AM
Nour Alnaser
Nour Alnaser - avatar
+ 2
yes exactly it is 0! cool! never thought about it
14th Mar 2017, 1:30 PM
Abbosjon Kudratov
Abbosjon Kudratov - avatar
+ 1
Yes, it is, but more,try this code bool y=5; cout<<y; So, All the numbers in the language c++ are true, but after store into bool variable there is only 1 value,
13th Mar 2017, 5:47 AM
Petr Hatina
Petr Hatina - avatar
+ 1
We can make this kind program for java
14th Mar 2017, 3:29 AM
Shah074437 Hotak
Shah074437 Hotak - avatar