>
>
Is size_t a standard type in C++? And i…

Andrey Karpov
Articles: 643

Is size_t a standard type in C++? And in C?

size_t is a base unsigned integer memsize-type defined in the standard library of C/C++ languages. This type is described in the header file stddef.h for C and in the file cstddef for C++. Types defined by the header file stddef.h are located in the global namespace while cstddef places the size_t type in the namespace std. Since the standard header file stddef.h of the C language is included into C++ programs for the purpose of compatibility, in these programs you may address the type both in the global namespace (::size_t, size_t) and namespace std (std::size_t).

Note that the size_t type is not a reserved word of C/C++ languages and is defined through the typedef specifier in the standard header file as a type of the result returned by the sizeof operator and is chosen so that it could store the maximum size of a theoretically possible array of any type, i.e. size_t will be 32-bit on a 32-bit system and 64-bit on a 64-bit one.

References