Chapter 5. Expressions and Operators

An expression consists of a sequence of constants, identifiers, and operators that the program evaluates by performing the operations indicated. The expression’s purpose in the program may be to obtain the resulting value, or to produce side effects of the evaluation, or both (see “Side Effects and Sequence Points”).

A single constant, string literal, or the identifier of an object or function is in itself an expression. Such a simple expression, or a more complex expression enclosed in parentheses, is called a primary expression. The C11 standard adds another kind of primary expression, the generic selection, which is described in the next section.

Every expression has a type. An expression’s type is the type of the value that results when the expression is evaluated. If the expression yields no value, it has the type void. Some simple examples of expressions are listed in Table 5-1 (assume that a has been declared as a variable of type int, and z as a variable of type float _Complex).

Table 5-1. Example expressions
Expression Type

'\n'

int

a + 1

int

a + 1.0

double

a < 77.7

int

"A string literal."

char *

abort()

void

sqrt(2.0)

double

z / sqrt(2.0)

double _Complex

As you can see from the last example in Table 5-1, compound expressions are formed by using an operator with expressions as its operands. The operands can themselves be primary or compound expressions. For example, you can use a function call as a factor in ...

Get C in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.