size_t - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# size_t

From cppreference.com
< c‎ | types

Defined in header `<stddef.h>` |  |
Defined in header `<stdio.h>` |  |
Defined in header `<string.h>` |  |
Defined in header `<time.h>` |  |
typedef /*implementation-defined*/ size_t; |  |

size_t is the unsigned integer type of the result of `sizeof` , alignof (since C11) and offsetof.

### [edit] Notes

size_t can store the maximum size of a theoretically possible object of any type (including array).

size_t is commonly used for array indexing and loop counting. Programs that use other types, such as unsigned int, for array indexing may fail on, e.g. 64-bit systems when the index exceeds UINT_MAX or if it relies on 32-bit modular arithmetic.

### [edit] Example

Run this code

    #include <stdio.h>
    #include <stddef.h>
    #include <stdint.h>

    int main(void)
    {
        const size_t N = 100;
        int numbers[N];
        for (size_t ndx = 0; ndx < N; ++ndx)
            numbers[ndx] = ndx;
        printf("SIZE_MAX = %lu\n", SIZE_MAX);
        size_t size = sizeof(numbers);
        printf("size = %zu\n", size);

        return 0;
    }

Possible output:

    SIZE_MAX = 18446744073709551615
    size = 400

### [edit] See also

ptrdiff_t | signed integer type returned when subtracting two pointers (typedef) [edit]
offsetof | byte offset from the beginning of a struct type to specified member (function macro) [edit]
C++ documentation for size_t

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/types/size_t&oldid=75338"