Skip to content
Search

C:ptrdiff t

lastmod 2016-11-17created 2015-04-063 edits

Result of pointer subtraction.

Alias of one of the fundamental signed integer types.

It is a type able to represent the result of any valid pointer subtraction operation.

A pointer subtraction is only guaranteed to have a valid defined value for pointers to elements of the same array (or for the element just past the last in the array).

Visual Studio comment

ANSI 3.3.6, 4.1.1 The integer type required to hold the difference between two pointers to elements of the same array, ptrdiff_t.

ptrdiff_t is a signed int.

Array Indexing

When indexing an array, use ptrdiff_t rather than the usual int, because the maximum size differs between 32-bit and 64-bit, and in particular it can exceed INT_MAX. The maximum and minimum values are given by PTRDIFF_MAX and PTRDIFF_MIN.

Favorite site