Home  >  Article  >  Operation and Maintenance  >  How many bytes are short in Linux?

How many bytes are short in Linux?

WBOY
WBOYOriginal
2022-07-13 10:40:464279browse

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.

How many bytes are short in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How many bytes are there in short in Linux

How many bytes are short in Linux?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn