size_t
cppreference.com
<tbody>
</tbody>
| <stddef.h> 에 정의되어 있음.
|
||
| <stdio.h> 에 정의되어 있음.
|
||
| <stdlib.h> 에 정의되어 있음.
|
||
| <string.h> 에 정의되어 있음.
|
||
| <time.h> 에 정의되어 있음.
|
||
| <uchar.h> 에 정의되어 있음.
|
(since C11) |
|
| <wchar.h> 에 정의되어 있음.
|
(since C95) |
|
typedef /*implementation-defined*/ size_t; |
||
size_t is the unsigned integer type of the result of sizeof , _Alignof (since C11) and offsetof, depending on the data model.
|
The bit width of |
(since C99) |
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.
Example
코드 실행
#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 = %zu\n", SIZE_MAX);
size_t size = sizeof numbers;
printf("size = %zu\n", size);
}
Possible output:
SIZE_MAX = 18446744073709551615
size = 400
References
- C11 standard (ISO/IEC 9899:2011):
- 7.19 Common definitions <stddef.h> (p: 288)
- 7.20.3 Limits of other integer types (p: 293)
- C99 standard (ISO/IEC 9899:1999):
- 7.17 Common definitions <stddef.h> (p: 253)
- 7.18.3 Limits of other integer types (p: 258)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.1.6 Common definitions <stddef.h>
See also
| 두 포인터를 뺀 경우에 부호있는 정수 타입을 반환한다. (typedef) | |
| byte offset from the beginning of a struct type to specified member (function macro) | |
C++ documentation for size_t
| |