gpt4 book ai didi

c - C 中的 size_t 是什么?

转载 作者:行者123 更新时间:2023-11-30 16:40:12 24 4
gpt4 key购买 nike

我对 C 中的 size_t 感到困惑。我知道它是由 sizeof 运算符返回的。但它到底是什么?它是一种数据类型吗?

假设我有一个 for 循环:

for(i = 0; i < some_size; i++)

我应该使用int i;还是size_t i;

最佳答案

From Wikipedia :

According to the 1999 ISO C standard (C99), size_t is an unsigned integer type of at least 16 bit (see sections 7.17 and 7.18.3).

size_tis an unsigned data type defined by several C/C++ standards, e.g. the C99 ISO/IEC 9899 standard, that is defined in stddef.h.1 It can be further imported by inclusion of stdlib.h as this file internally sub includes stddef.h.

This type is used to represent the size of an object. Library functions that take or return sizes expect them to be of type or have the return type of size_t. Further, the most frequently used compiler-based operator sizeof should evaluate to a constant value that is compatible with size_t.

暗示,size_t 是保证保存任何数组索引的类型。

关于c - C 中的 size_t 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46762566/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com