Course List http://www.c-jump.com/bcc/
(x + 7) addition
(a - b) subtraction
(x * y) multiplication
(x / y) division
(r % s) modulus
Yields integer quotient
Integer numerator and denominator
No rounding occurs
Examples:
(7 / 4) equals to 1
(17 / 5) equals to 3
int main()
{
int x = (7 / 4); // x == 1
int y = (17 / 5); // y == 3
return 0;
}
Yields remainder after integer division
Integer operands only
No rounding occurs
Examples:
(7 % 4) equals to 3
(17 % 5) equals to 2
int main()
{
int x = (7 % 4); // x == 3
int y = (17 % 5); // y == 2
return 0;
}
Decision making:
(x > y) is x greater than y?
(x < y) is x less than y?
(x >= y) is x greater than or equal to y?
(x <= y) is x less than or equal to y?
Decision making:
(x == y) is x equal to y?
(x != y) is x not equal to y?
Compare to:
!(x == y) isn't x equal to y?
Note: avoid confusion between equality (==) and assignment (=).
Immutable property of all C++ operators
There are two types of associativity,
right-to-left associativity:
assignment operator:
a = b = c is interpreted as a = ( b = c )
unary operators:
!!b is interpreted as !( !b )
left-to-right associativity:
arithmetic and other binary operators:
a + b + c is interpreted as ( a + b ) + c
Decision making
(condition) ? expressiontrue : expressionfalse
For example,
int main()
{
int x = 5;
int y = 8;
int z = ( x > y ) ? x : y; // select max value
return 0;
}
Assign values to variables:
int main()
{
int x;
int y;
int z;
x = 1;
y = x;
x += y; // x = x + y;
z *= 3; // z = z * 3;
return 0;
}
The last two operators,
+= and *=
are known as arithmetic assignment operators. They are pronounced as "add and assign," "multiply and assign ," respectively.
|
|
if ( exp1 && exp2 ) {
//...
}
|
#include <cassert>
void main()
{
int x = 1;
int y = 2;
// true: y > x
// true: x > 0
if ( y > x && x > 0 ) {
assert( y > x );
assert( x > 0 );
}
}
|
if ( exp1 || exp2 ) {
//...
}
|
void main()
{
int x = 1;
int y = 2;
if ( x == 1 || y == 2 ) {
//...
}
}
|
|
void main()
{
int x = 1;
int y = 2;
if ( x == y && y > 0 ) {
// execution nevert gets here...
}
// expr y > 0 never evaluated!
if ( x == 1 || y == 2 ) {
// expr y == 2 never evaluated!
// ...
}
}
|