C language: size_t Type – Add-on Type size_t

Tram Ho

size_t – size type – is a non-negative integer type whose width depends on OS support and is not less than 16-bit . size_t is defined in the libraries:

  • <stddef.h>
  • <stdio.h>
  • <stdlib.h>
  • <string.h>
  • <time.h>
  • <uchar.h>
  • <wchar.h>

In standard C code, the size_t type is often used for index variables to access arrays and counter variables that count for loops instead of the unsigned int integer type. The reason is because the design of unsigned int has a fixed width of 32-bit and can cause overflow if used to count tuples or large loops in 64-bit programs.



In addition, size_t is also used in places to type return values ​​and parameters of standard library functions such as sizeof , offsetof , bsearch , qsort , etc..
Share the news now

Source : Viblo