P. 1
C Language Reference Manual - 5th Edition

C Language Reference Manual - 5th Edition

4.5

|Views: 8,347|Likes:
Published by ioana

More info:

Published by: ioana on May 23, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/16/2013

pdf

text

original

The additive operators + and - associate from left to right. The usual arithmetic
conversions are performed.The syntax for the additive operators is as follows:

additive-expression:

multiplicative-expression

additive-expression + multiplicative-expression

additive-expression - multiplicative-expression

In addition to arithmetic types, the following type combinations are acceptable for
additive expressions:

• For addition, one operand is a pointer to an object type and the other operand is
an integral type.

• For subtraction,

– Both operands are pointers to qualified or unqualified versions of compatible
object types.

– The left operand is a pointer to an object type, and the right operand has
integral type.

The result of the + operator is the sum of the operands. The result of the - operator is
the difference of the operands.

When an operand of integral type is added to or subtracted from a pointer to an
object type, the integral operand is first converted to an address offset by multiplying
it by the length of the object to which the pointer points. The result is a pointer of the
same type as the original pointer.

007–0701–150

59

6: Expressions and Operators

For instance, suppose a has type “array of ”, and p has type “pointer to
” and points to the initial element of a. Then the result of p + n, where n is
an integral operand, is the same as &a[n].

If two pointers to objects of the same type are subtracted, the result is converted (by
division by the length of the object) to an integral quantity representing the number
of objects separating them. Unless the pointers point to objects in the same array, the
result is undefined. The actual type of the result is int in traditional C, and
ptrdiff_t (defined in as int in -o32 and -n32 modes and as long
in -64 mode) in ANSI C.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->