I see variables defined with this type but I don\'t know where it comes from, nor what is its purpose. Why not use int or unsigned int? (What about other \"similar\" types?
This way you always know what the size is, because a specific type is dedicated to sizes. The very own question shows that it can be an issue: is it an int or an unsigned int? Also, what is the magnitude (short, int, long, etc.)?
Because there is a specific type assigned, you don't have to worry about the length or the signed-ness.
The actual definition can be found in the C++ Reference Library, which says:
Type:
size_t(Unsigned integral type)Header:
size_tcorresponds to the integral data type returned by the language operatorsizeofand is defined in theheader file (among others) as an unsigned integral type.In
, it is used as the type of the parameternumin the functionsmemchr,memcmp,memcpy,memmove,memset,strncat,strncmp,strncpyandstrxfrm, which in all cases it is used to specify the maximum number of bytes or characters the function has to affect.It is also used as the return type for
strcspn,strlen,strspnandstrxfrmto return sizes and lengths.