size_t and ptrdiff_t

Z

zloy tapok

Hello guys,

What is the meaning of the size_t and prtdiff_t types?
Are there an examples of using such types?

Thank you in advance.
 
E

Eric Sosman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

size_t, ssize_t and ptrdiff_t 56
Plauger, size_t and ptrdiff_t 26
ptrdiff_t 6
ptrdiff_t 13
size_t in inttypes.h 4
What's the deal with size_t? 104
size_t in a struct 24
usage of size_t 190

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top