TTS Swift Notes: Basic Operators Flashcards
What is an operator?
A special symbol or phrase that one uses to check, change, or combine values. EX: +, &&, ++i, etc
What are the arithmetic operators?
+, -, *, /, % (modulo)
- 1 + 2 // equals 3
- 5 - 3 // equals 2
- 2 * 3 // equals 6
10. 0 / 2.5 // equals 4.0
What are the two range operators?
a..<b></b>
What are the three kinds of operators?
Unary, binary, and ternary.
What do unary operators operate on?
A single target (EX: -a, !b, i++)
What do binary operators operate on?
Two targets (EX: 2 + 3)
What does the ternary operator operate on?
Three targets. (EX: a ? b : c)
What is an operand?
A value that an operator affects.
What does an assignment operator do?
The assignment operators (a = b) initializes or updates the value of a with the value of b.
- let b = 10
- var a = 5
- a = b
- // a is now equal to 10
- What is the symbol for the increment operator?
++
What is the symbol for the decrement operator?
–
The increment and decrement operators change the value by how many?
One
- ++i is shorthand for what?
i = i + 1
–i is shorthand for what?
i = i - 1
If the operator is written before the variable, it increments the variable _______ returning its value.
Before