Home > Article > Operation and Maintenance > How many bytes are short in Linux?
In Linux, short occupies 2 bytes in both 32-bit and 64-bit platforms; in Linux, only long and void (in C language, void is an "indeterminate type") are It is 4 bytes in 32-bit and 8 bytes in 64-bit.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
It can be seen that there are only long (long integer type), void* (in c language, void is "not Determine the type"), 4 bytes in 32-bit, 8 bytes in 64-bit.
Extended knowledge
char occupies 1 byte, short occupies 2 bytes, int, float, and long all occupy 4 bytes, and double occupies 8 bytes
The pointer length is related to the address bus. Because the pointer records an address, the 32-bit one is 4 bytes, and the 64-bit one is 8 bytes.
I found a problem. The following code was run under win10 64-bit system. It should be said that int occupies 8 bytes, but later I thought wrong; the project I created is a win32 console application, which means The compiler is 32-bit - "How many bytes an int occupies is determined not only by the compiler, but also by the CPU or virtual machine or operating system, but in the final analysis it is determined by the compiler."
64-bit win10 Next, the result of
#include "iostream" using namespace std; int main() { double *p = NULL; cout<<sizeof(char)<<endl; cout<<sizeof(short)<<endl; cout<<sizeof(int)<<endl; cout<<sizeof(float)<<endl; cout<<sizeof(long)<<endl; cout<<sizeof(double)<<endl; cout<< sizeof(char *) << sizeof(short *) << sizeof(int *) << sizeof(p) << sizeof(double *)<<endl; return 0; }
under codeblocks win32 console is:
1 2 4 4 4 8 44444
As can be seen from the above, char occupies 1 byte, short occupies 2 bytes, and int, float, and long all occupy 4 bytes. , double occupies 8 bytes, and any type of pointer occupies 4 bytes;
Recommended learning:Linux video tutorial
The above is the detailed content of How many bytes are short in Linux?. For more information, please follow other related articles on the PHP Chinese website!