std::ptrdiff_t
Template:cpp/types/sidebar Template:ddcl list begin <tr class="t-dsc-header">
<td><cstddef>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td class="t-dcl-nopad"><td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end
Template:cpp is the signed integer type of the result of subtracting two pointers.
Notes
Template:cpp is used for pointer arithmetic and array indexing, if negative values are possible. Programs that use other types, such as Template:cpp, may fail on, e.g. 64-bit systems when the index exceeds Template:cpp or if it relies on 32-bit modular arithmetic.
When working with the C++ container library, the proper type for the difference between iterators is the member typedef Template:cpp, which is often synonymous with Template:cpp.
Only pointers to elements of the same array (including the pointer one past the end of the array) may be subtracted from each other.
If an array is so large (greater than Template:cpp elements, but less than Template:cpp bytes), that the difference between two pointers may not be representable as Template:cpp, the result of subtracting two such pointers is undefined.
For char arrays shorter than Template:cpp, Template:cpp acts as the signed counterpart of Template:cpp: it can store the size of the array of any type and is, on most platforms, synonymous with Template:cpp).
Example
See also
unsigned integer type returned by the sizeof operator (typedef) | |
byte offset from the beginning of a standard-layout type to specified member (function macro) |