On this page
size_t
Prev: stddef.h | Up: stddef.h | Next: ptrdiff_t
Rel: stddef.h, stdint, stdbool & limits Guide
Ref: cppreference — size_t
Tags: #public #prog #c #stdlib #stddef #tier/core
Include
#include <stddef.h>
Signature & Overview
typedef /* unsigned */ size_t;
Unsigned integer type returned by sizeof and used for object sizes and array indices.
Notes & Pitfalls
- Unsigned integer for sizes and indices (
%zuinprintf): Beware underflow in reverse loops (for (size_t i = n; i-- > 0;)instead ofi >= 0, which loops forever!).
Example
#include <assert.h>
#include <stddef.h>
int main(void) {
size_t n = 4, sum = 0;
for (size_t i = n; i-- > 0;) sum += i;
assert(sum == 6);
}
Linked from
Related notes
- tuts/c/stdlib/stddef/ptrdiff_t Linked here; links to this page; shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/stddef Linked here; links to this page; shared tags: #c, #prog, #stddef, #stdlib
- tuts/c/builtins/sizeof links to this page; shared tags: #c, #prog, #tier
- tuts/c/stdlib/stdint_stdbool_and_limits Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stddef/max_align_t shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/stddef/NULL shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/stddef/offsetof shared tags: #c, #prog, #stddef, #stdlib, #tier
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier