Beginner CPP I would like to ask that the memory occupied by the short type must be less than the memory occupied by the int type?

the book says, "if short is smaller than int, then using short can save memory."
do not understand "if short is smaller than int"
CPP stipulates that short at least 16 bits int is at least as long as short
so when will short be larger than int?

CPP
Apr.05,2021

means that different compilers may differ in details


short will not be larger than int


the same compilation environment, and it is true that the short type will not be greater than int


if in all systems, the width of each type is the same, it will be very convenient to use, for example, short is always 16-bit, int is always 32-bit, and so on; but life is not that simple, your CPP code may run on different terminals, such as 32-bit machines, 64-bit machines, or even run on ancient single-chip microcontrollers, etc., the word length of CPU is different in these different environments.

attached reference article: those details of CPP-- differences between 32-bit and 64-bit data types

so in order to adapt to different hardware environments as much as possible, CPP provides a flexible standard to make your code more portable:

  • short at least 16 bits
  • int is at least as long as short;
  • long is at least 32 bits and at least as long as int
  • long long at least 64 bits and at least as long as long

because it is the standard of CPP, as long as you are using a compiler that conforms to the CPP specification, it is inevitable that short saves more memory than int.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b401c7-40a74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b401c7-40a74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?