在C语言中,“short int”和“int”的区别是什么?

我今天正在处理同样的问题。我的结论是,它取决于程序执行所在的机器架构的字长。

根据C99 limits.h文档。

/* Minimum and maximum values a `signed short int' can hold. */

# define SHRT_MIN (-32768)

# define SHRT_MAX 32767

/* Maximum value an `unsigned short int' can hold. (Minimum is 0.) */

# define USHRT_MAX 65535

/* Minimum and maximum values a `signed int' can hold. */

# define INT_MIN (-INT_MAX - 1)

# define INT_MAX 2147483647

/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */

# define UINT_MAX 4294967295U

/* Minimum and maximum values a `signed long int' can hold. */

# if __WORDSIZE == 64

# define LONG_MAX 9223372036854775807L

# else

# define LONG_MAX 2147483647L

# endif

# define LONG_MIN (-LONG_MAX - 1L)

/* Maximum value an `unsigned long int' can hold. (Minimum is 0.) */

# if __WORDSIZE == 64

# define ULONG_MAX 18446744073709551615UL

# else

# define ULONG_MAX 4294967295UL

# endif

如果有更好的答案,请告诉我。