Programming and Graphics

(Kiana) #1

50 Introduction to C++ Programming and Graphics


Equal to a==b
Not equal to a!=b
Less than a<b
Less than or equal to a<=b
Greater than a>b
Greater than or equal to a>=b
And A&&B
Or A||B
Boolean opposite or true or false !A
Conditional operator A?a: b;

Table 3.1.2Relational and logical operands in C++;a, bare variables, andA, B
are expressions. The conditional operator shown in the last entry returns the
value of the variableaif the statementAis true, and the value of the variable
bif the statementAis false.


Threading


The statement:

c = (a=1, b=2, a+b);

is a compact representation of the statements:


a=1;
b=2;
c=a+b;

In these constructions, the variablecis evaluated from the rightmost expression
inside the parentheses.


Byte size operator


To find how many memory bytes are allocated to the variablea,weuse
thesizeofoperator:


b = sizeof(a);

wherebhas been declared as an integer.


The practical usage of the C++ operators discussed in this section will
be demonstrated in following chapters by numerous applications.

Free download pdf