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 the section "Side Effects and Sequence Points," later in this chapter).

A single constant, a 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.

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 examples 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 a multiplication. Likewise, the arguments in a function call can be expressions involving several operators, as in this example:

 2.0 * sin( 3.14159 * fAngleDegrees/180.0 ) 



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net