logical and bitwise operators of C++

The | and ||, & and && operators are used differently.
-| operator is an OR operator to work with bits (0 and 1)
-|| operator is a logical OR operator to work with boolean values (true and false)
-& operator is an AND operator to work with bits (0 and 1)
-&& operator is an AND operator to work with boolean values (true and false)

int a=2, b=3, res1, res2;
res1=a | b; //res1=3
res2=a || b; //res2=1 meaning true

Posted by: sam | post date: 12-15-2012 | Subject: C++ Programming Language




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.