a=b=false; сout<<a|| !b; почему отсюда выходит 0? тогда как сout<< !a||b выходит 1??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

a=b=false; сout<<a|| !b; почему отсюда выходит 0? тогда как сout<< !a||b выходит 1???

пожалуйста уделите мне немного времени,заранее спасибо

12th Nov 2017, 12:35 PM
pro
pro - avatar
3 Answers
+ 5
Просто добавьте скобки и работайте правильно 😃 #include <iostream> using namespace std; int main() { bool a = false, b = false; cout << (a || !b); return 0; }
12th Nov 2017, 1:36 PM
Vukan
Vukan - avatar
+ 1
It's a question of precedence (priority). Priority of << is higher than ||. https://code.sololearn.com/ccmRj9zntciA/?ref=app
12th Nov 2017, 1:37 PM
Nadir SOUALEM
Nadir SOUALEM - avatar
+ 1
If you just write cout<<a||!b then it will output the value of a, when cout<<(a||!b) would give you the result of the logic in brackets, same with !a||b (Если просто написать cout<<a||!b то программа возвратит a но если добавить скобки как в cout<<(a||!b) то тогда будет возвращен результат логики в скобках, тоже самое и с !a||b) here is the code for you to understand it better (Посмотри этот код, будет легче разобраться): https://code.sololearn.com/c7Wf4DOX6MoW
12th Nov 2017, 1:59 PM
Rey
Rey - avatar