AP CSP: Unit 1: Operators
operators
... are symbols which you can use to modify or combine values. In addition to having operators that perform basic mathematical operations like addition, subtraction, multiplication, and division, C also has operators that perform other functions: like finding the remainder when dividing, or updating the value of a variable.
=
... is called an assignment operator. It looks like a mathematic equal sign, but it has a different function. The assignment operator makes a value, equal to whatever's on the right side of the equals sign:. Ex. e = f + 1; (if f was the value 1 then this would return the value 2) provide a variety of ways to update the value of a variable.
%
...is called the modulus operator, which gives us the remainder when the number on the left of the operator is divided by the number on the right. Ex. int f = 13 % 3; would return the value 1.
/=
will set a variable to its existing value divided by some other number.
-=
will set a variable to its existing value minus some other number.
*=
will set a variable to its existing value multiplied by some other number.
+=
will set a variable to its existing value plus some other number.
+
The arithmetic operator which adds two numbers, (-), (*) , (/) .
/
The arithmetic operator which divides one number by another (Ints can only store whole numbers, so if you divide 10/3 you will receive the int 3. If you want to receive the value with decimal points you can use the data type float).
*
The arithmetic operator which multiplies two numbers
-
The arithmetic operator which subtracts one number from another
arithmetic operators
C's ... perform mathematical functions on numbers.
assignment operators
C's ... provide a variety of ways to update the value of a variable