Node:Expressions and operators, Next:Parameters, Previous:Scope, Up:Top
Expressions and operators
Thinking in C. Short strings of code.
An operator is a character or string of characters used as a built-in function. We have already experimented with one operator in C: the cast operator.
An operator is so called because it takes one or more values and
operates on them to produce a result. For example, the addition
operator +
can operate on the values 4 and 5 to produce the
result 9. Such a procedure is called an operation, and any value
operated on (such as 4 and 5 in this example) is called an
operand.
There are many operators in C. Some of them are familiar, such as the
addition operator +
and subtraction operator -
. Most
operators can be thought of as belonging to one of three groups,
according to what they do with their operands:
- Mathematical operators, such as the addition operator
+
in100 + 500
, or the multiplication operator*
in12 * 2
. - Comparison operators (a subset of mathematical operators), such as the
less-than operator
<
and the greater-than operator>
. - Operators that produce new variable types, such as the cast operator.
The majority of operators fall into the first group. The second group is a subset of the first set; in this second set, the result of an operation is a Boolean value (a value of either true or false).
C has about forty different operators. The chief object of this chapter is to explain the basic operators in C. We will examine more complex operators in another chapter. (See Advanced operators.)