C++ logical operators

C++ logical operators

This is a small tutorial/clarification on C++ logical operators & , | , && and ||.

Consider this C++ source file:
#include using namespace std;

int main(int argc, const char* argv [] ){ //Proving conclusion: cout<<"Proving conclusion: "; cout<< (0x7 & 0x2)<

= Conclusion: =

| and &: Are bitwise operators.
Operate on all the bits and return the comparison.

ex:
111 & 010 = 010
110 | 001 = 111

|| and &&: Are boolean logical operators.
Will evaluate if each value is true or false, then return the boolean operation's result.
ex:
111 && 000 = (1 AND 0) = 0
111 || 000 = (1 OR 0) = 1
beware:
10 && 01 = (1 AND 1) = 1
10 || 01 = (1 OR 1) = 1


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Logical connective — This article is about connectives in classical logic. For connectors in natural languages, see discourse connective. For connectives and operators in other logics, see logical constant. For other logical symbols, see table of logic symbols. In… …   Wikipedia

  • Operators in C and C++ — This is a list of operators in the C and C++ programming languages. All the operators listed exist in C++; the fourth column Included in C , dictates whether an operator is also present in C. Note that C does not support operator overloading.… …   Wikipedia

  • Logical NOR — This article is about NOR in the logical sense. For the electronic gate, see NOR gate. For other uses, see Nor. Venn diagram of In boolean logic, logical nor or joint denial is a truth functional operator which produces a result that is the… …   Wikipedia

  • Logical disjunction — Disjunction redirects here. For separation of chromosomes, see Meiosis. For disjunctions in distribution, see Disjunct distribution. Venn diagram of the logical disjunction of A and B …   Wikipedia

  • logical constants — The expressions selected to indicate the logical form of a sentence. A sentence will play a proper role in inference in virtue of a structure that can be exhibited by means of these expressions. The basic logical constants include expressions for …   Philosophy dictionary

  • Logical shift — In computer science, a logical shift is a shift operator that shifts all the bits of its operand. Unlike an arithmetic shift, a logical shift does not preserve a number s sign bit or distinguish a number s exponent from its mantissa; every bit in …   Wikipedia

  • operators — op·er·a·tor || É‘pÉ™reɪtÉ™(r) / É’p n. one who activates; worker of a telephone switchboard; worker; operation symbol, character which signifies a logical or mathematical operation between several numbers (Computers) …   English contemporary dictionary

  • JavaScript syntax — This article is part of the JavaScript series. JavaScript JavaScript syntax JavaScript topics This box: view · …   Wikipedia

  • Propositional calculus — In mathematical logic, a propositional calculus or logic (also called sentential calculus or sentential logic) is a formal system in which formulas of a formal language may be interpreted as representing propositions. A system of inference rules… …   Wikipedia

  • Relational operator — In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality (e.g., 5 = 5) and inequalities (e.g.,… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”