13.07.2015 Views

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Relational OperatorsLogical operators and ValuesBoth Fortran and C/<strong>C++</strong> define relational operatorsFortran Purpose C or <strong>C++</strong>X .LT. Y less than x < yX .LE. Y less than or equal x yX .GE. Y greater than or equal x >= yX .EQ. Y equal x == yX .NE. Y not equal x != y• zero is false and non-zero is true• Warning: a common mistake isint i, j;// some code setting i and jif ( i = j ) {// some stuff}this sets i = j and <strong>the</strong>n does some stuff if j isnon-zeroBoth Fortran and C/<strong>C++</strong> have logical operations andvaluesFortran Purpose C or <strong>C++</strong>.FALSE. false value 0.TRUE. true value non-zero.NOT. X logical negation !xX .AND. Y logical and x && yX .OR. Y logical inclusive or x || y• any expression has a logical resultif ( i = j(k) ) {// do some stuff}• && and || evaluate from left to right and right handexpression not evaluated if it doesn’t need to be• <strong>the</strong> following never divides by zeroif ( d && (x/d < 10.0) ) {// do some stuff}• if bool type is supported, <strong>the</strong> true and false existsas constants.<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 13 Paul F. Kunz<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 14 Paul F. Kunz

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!