Go to the first, previous, next, last section, table of contents.

Statements and Expressions

Operators act upon objects of a certain type or types and specify what is to be done to them. Expressions combine variables and constants to create new values. Statements are expressions, assignments, function calls, or control flow statements which make up C programs.

Operators

Each of the data types has its own set of operators that determine which operations may be performed on them.

Integer Operations

The following operations are supported on integers:

Long Integers

A subset of the operations implemented for integers are implemented for long integers: arithmetic addition +, subtraction -, and multiplication *, and the integer comparison operations. Bitwise and boolean operations and division are not supported.

Floating Point Numbers

IC uses a package of public-domain floating point routines distributed by Motorola. This package includes arithmetic, trigonometric, and logarithmic functions.

The following operations are supported on floating point numbers:

Characters

Characters are only allowed in character arrays. When a cell of the array is referenced, it is automatically coerced into a integer representation for manipulation by the integer operations. When a value is stored into a character array, it is coerced from a standard 16-bit integer into an 8-bit character (by truncating the upper eight bits).

Assignment Operators and Expressions

The basic assignment operator is =. The following statement adds 2 to the value of a.

a = a + 2;

The abbreviated form

a += 2;

could also be used to perform the same operation.

All of the following binary operators can be used in this fashion:

+   -   *   /   %   <<   >>   &   ^   |

Increment and Decrement Operators

The increment operator "++" increments the named variable. For example, the statement "a++" is equivalent to "a= a+1" or "a+= 1".

A statement that uses an increment operator has a value. For example, the statement

a= 3;
printf("a=%d a+1=%d\n", a, ++a);

will display the text "a=3 a+1=4."

If the increment operator comes after the named variable, then the value of the statement is calculated after the increment occurs. So the statement

a= 3;
printf("a=%d a+1=%d\n", a, a++);

would display "a=3 a+1=3" but would finish with a set to 4.

The decrement operator "--" is used in the same fashion as the increment operator.

Data Access Operators

&
A single ampersand preceeding a variable, an array reference, or a structure element reference returns a pointer to the location in memory where that information is being stored. This should not be used on arbitrary expressions as they do not have a stable place in memory where they are being stored.
*
A single star preceeding an expression which evaluates to a pointer returns the value which is stored at that address. This process of accessing the value stored within a pointer is known as dereferencing.
[expr]
An expression in square braces following an expression which evaluates to an array (an array variable, the result of a function which returns an array pointer, etc.) checks that the value of the expression falls within the bounds of the array and references that element.
.
A dot between a structure variable and the name of one of its fields returns the value stored in that field.
->
An arrow between a pointer to a structure and the name of one of its fields in that structure acts the same as a dot does, except it acts on the structure pointed at by it's left hand side. Where f is a structure of a type with e as an element name, the two expressions f.i and (&f)->i are equivalent.

Precedence and Order of Evaluation

The following table summarizes the rules for precedence and associativity for the C operators. Operators listed earlier in the table have higher precedence; operators on the same line of the table have equal precedence.

Operator Associativity
() [] left to right
! ~ ++ -- - (type) right to left
* / % left to right
+ - left to right
<< >> left to right
< <= > >= left to right
== != left to right
& left to right
^ left to right
| left to right
&& left to right
|| right to left
= += -= etc. right to left
, left to right

Go to the first, previous, next, last section, table of contents.