size_t
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   在标头  <stddef.h> 定义
  | 
||
|   在标头  <stdio.h> 定义
  | 
||
|   在标头  <stdlib.h> 定义
  | 
||
|   在标头  <string.h> 定义
  | 
||
|   在标头  <time.h> 定义
  | 
||
|   在标头  <uchar.h> 定义
  | 
(C11 起)  | 
|
|   在标头  <wchar.h> 定义
  | 
(C95 起)  | 
|
|   typedef /*implementation-defined*/ size_t;  | 
||
size_t 是 sizeof 、 _Alignof (C11 起) 和 offsetof 的结果的无符号整数类型,定义取决于数据模型。
| 
 
  | 
(C99 起) | 
注解
size_t 能存储理论上可行的任何类型(包括数组)对象的最大大小。
size_t 通常用于数组下标和循环计数。将如 unsigned int 的其他类型用作数组下标的的程序,可能在 64 位系统上失败,例如在下标超过 UINT_MAX 时,或若依赖 32 位模算术。
示例
运行此代码
可能的输出:
SIZE_MAX = 18446744073709551615 size = 400
引用
- C11 标准(ISO/IEC 9899:2011):
 
- 7.19 Common definitions <stddef.h> (第 288 页)
 
- 7.20.3 Limits of other integer types (第 293 页)