Assignments Expressions Operator 


C Programming Tutorial 

Go to the Table of Contents

 

Assignments, Expressions and Operators

Thinking in C. Working things out.

An operator is something which takes one or more values and does something useful with those values to produce a result. It operates on them. The terminology of operators is the following:

operator
Something which operates on someting.
operand
Each thing which is operated upon by an operator is called an operand.
operation
The action which was carried out upon the operands by the operator!

There are lots of operators in C. Some of them may already be familiar:

 + - * / = & ==

Most operators can be thought of as belonging to one of three groups, divided up arbitrarily according to what they do with their operands. These rough groupings are thought of as follows:

  • Operators which produce new values from old ones. They make a result from their operands. e.g. +, the addition operator takes two numbers or two variables or a number and a variable and adds them together to give a new number.
  • Operators which make comparisons. e.g. less than, equal to, greater than...
  • Operators which produce new variable types: like the cast operator.

The majority of operators fall into the first group. In fact the second group is a subset of the first, in which the result of the operation is a boolean value of either true of false.

C has no less than thirty nine different operators. This is more than, say, Pascal and BASIC put together! The operators serve a variety of purposes and they can be used very freely. The object of this chapter is to explain the basics of operators in C. The more abstruse operators are looked at in another chapter.