Hello guys,
What is the meaning of the size_t and prtdiff_t types?
Are there an examples of using such types?
size_t is the type of the result produced by the sizeof operator.
It is an unsigned integer type that is able to hold values at least
as large as 65535, possibly larger. Each C implementation defines
its own version of size_t (just as each C implementation defines its
own version of int). It is most frequently used to express the sizes
of things: The amount of memory requested from malloc(), the length
of a string as determined by strlen(), and so on. It is also useful
as an array index when the array's size is unknown and possibly large.
ptrdiff_t is the type of the result of subtracting two pointers.
Subtraction can produce a positive, negative, or zero result, so
ptrdiff_t is a signed integer type. As with size_t (and int, and
so on), each implementation chooses its own version of ptrdiff_t,
but it must choose a type that can handle at least the values
-65535 through +65535, or possibly more. It is used less widely than
size_t, often appearing as a "transient" result that is immediately
stored in a variable of some other type. However, if you're dealing
with an array of unknown size and want to subtract two pointers and
store their difference for a while, a ptrdiff_t variable is the
thing to use.
If this isn't the information you're looking for, please
tell us more about what's confusing you.