In this blog we are going to be discussing operators!
Now, the simplest examples of operators are the arithmetic operators. Think of something like this:
5 + 5
The + sign is called an operator, and each of the two integers are called operands. The entire thing is called an expression.
But why does it really matter? Haven’t we already discussed how to do math in C like a million videos ago? Well the reason I am discussing operators more now is because there are actually many operators in C.
There are so many that we are going to be spending the next section of blogs discussing all of the different operators that are available to us. And no, not all operators are used for math. When we get into more complicated math, we tend to use what are known as functions, rather than operators.
The easiest way to start thinking about operators is to separate them into groups. You know we gotta group everything!
We can group the operators by the number of operands they work on. So the + operator has two operands, the first number and the second number. Operators with 2 operands are called binary operators. The other two classifications of operators are unary operators, which only work on one operand, and ternary operators, which work on three operands.
As we go through the operators, I want you to resist the urge to assume that operators change the values of stuff, because only a few do.
For example, if we have the expression x + 5, the value of x does not get changed by 5. The value of x always stays the same. This may seem obvious now, but as we get into some other operators keep this in mind. The ones that change values I will explicitly tell you that they do.
Grouping by number of operands can be helpful, but there is a more useful grouping that I am going teach you about. That is grouping the operators by function. For example, the + in 5 + 5 is part of the arithmetic operators.
Arithmetic operators is just one category of many operators. These are used for arithmetic. There are also relational operators, assignment operators, logical operators, and so forth.
So throughout the next section of videos you will likely see me using both classifications. So for example, + is a binary arithmetic operator. This allows you to understand a lot about the operator before you even start learning what it does.
In the next blog we are going to be discussing all of the arithmetic operators. Check it out!