Hidden Operators 

C Programming Tutorial 

Go to the Table of Contents

Vist the Gifcom Corporation

Hidden operators and values

Concise expressions

Many operators in C are more versatile than they appear to be, at first glance. Take, for example, the following operators

 = ++ -- += -= etc...

the assignment, increment and decrement operators... These innocent looking operators can be used in some surprising ways which make C source code very neat and compact.

The first thing to notice is that ++ and -- are unary operators: that is, they are applied to a single variable and they affect that variable alone. They therefore produce one unique value each time they are used. The assignment operator, on the other hand, has the unusual position of being both unary, in the sense that it works out only one expression, and also binary or dyadic because it sits between two separate objects: an "lvalue" on the left hand side and an expression on the right hand side. Both kinds of operator have one thing in common however: both form statements which have values in their own right. What does this mean? It means that certain kinds of statement, in C, do not have to be thought of as being complete and sealed off from the rest of a program. To paraphrase a famous author: "In C, no statement is an island". A statement can be taken as a whole (as a "black box") and can be treated as a single value, which can be assigned and compared to things! The value of a statement is the result of the operation which was carried out in the statement.

Increment/decrement operator statements, taken as a whole, have a value which is one greater / or one less than the value of the variable which they act upon. So:

 c = 5;


The second of these statement c++; has the value 6, and similarly:

 c = 5;


The second of these statements c--; has the value 4. Entire assignment statements have values too. A statement such as:

 c = 5;

has the value which is the value of the assignment. So the example above has the value 5. This has some important implications.