size_t vs int in C++ and/or C

后端 未结 9 1092
南方客
南方客 2020-12-01 07:51

Why is it that in C++ containers, it returns a size_type rather than an int? If we\'re creating our own structures, should we also be encouraged to

9条回答
  •  一生所求
    2020-12-01 08:22

    Some of the answers are more complicated than necessary. A size_t is an unsigned integer type that is guaranteed to be big enough to store the size in bytes of any object in memory. In practice, it is always the same size as the pointer type. On 32 bit systems it is 32 bits. On 64 bit systems it is 64 bits.

提交回复
热议问题