Learning C-Style C++


by Direct Approach Mentoring



+ - * / % == != > >= < <=

4. Operators

Operators are symbols which do something to two numbers like add them or multiply them.
Operators always return something. They can return numbers,

true

or

false

, etc.

+
Add

5

+

3

will return:

8

n +

6

will return: the current value of

n

plus

6

z + awill return: the current value of

z

plus the current value of

a

-
Subtract

8

-

5

will return:

3

apples -

2

will return: the current value of

apples

minus

2

100

- x
will return:

100

minus the current value of

x

*
Multiply

5

*

4

will return:

20

i *

10

will return: the current value of

i

times

10

 
/
Divide

10

/

2

will return:

5

10

/

3

will return:

3

(would be 3.333 but no decimals allowed)
n /

100

will return: the current value of

n

divided by

100

%
Remainder

12

%

5

will return:

2

(remainder)

15

%

5

will return:

0

(no remainder)
x %

3

will return: the remainder when you divide the current value of

x

by

3

==
Is equal?

13

==

13

will return:

true

13

==

7

will return:

false

n ==

5

will return:

true

only if the current value of

n

is

5

!=
Is not equal?

13

!=

13

will return:

false

13

!=

7

will return:

true

n !=

5

will return:

true

only if the current value of

n

is NOT

5

>
Is greater than?

50

>

49

will return:

true

5

>

5

will return:

false

(5 is not greater than itself)
n >

0

will return:

true

only if the current value of

n

is greater than

0

>=
Is greater than
or equal to?

50

>=

49

will return:

true

5

>=

5

will return:

true

(5 is not greater than itself, but it is equal to itself)
n >=

0

will return:

true

only if the current value of

n

is greater than or equal to

0

<
Is less than?

1

<

100

will return:

true

 
 
<=
Is less than
or equal to?

1

<=

100

will return:

true