Operator priority order in C++? | Sololearn: Learn to code for FREE!

+5

Operator priority order in C++?

Dear all, I don't know Why result of method 1 is 0? (Method 2: OK) Thanks! // #1: #include <iostream> using namespace std; int main() { cout<<0||1&&1; return 0; } Output: 0 // #2: #include <iostream> using namespace std; int main() { cout<<(0||1&&1); return 0; } Output: 1

c++

1/21/2019 5:22:59 AM

Nguyễn Văn Sơn

3 Answers

New Answer

+3

https://code.sololearn.com/WSJyHqt8xSIE/?ref=app

+3

https://stackoverflow.com/questions/49195740/the-output-of-cout-1-0

+2

Priority of operators is as follows:- NOT(!, ~) AND (&&) OR(||)