<>int How many bytes

On a whim today , Want to know C How many bytes does each integer occupy in the language .

Test the two environments with the code first ;
#include<stdio.h> #include<stdlib.h> int main() { printf("sizeof(int))
:%d\n",sizeof(int)); printf("sizeof(long) :%d\n",sizeof(long));
printf("sizeof(short) :%d\n",sizeof(short)); printf("sizeof(char)
:%d\n",sizeof(char)); printf("sizeof(float) :%d\n",sizeof(float));
printf("sizeof(double):%d\n",sizeof(double)); return 0; }
Here's where Dev-C++ 5.11 Test results in ( Compiler is gcc):

sizeof(int)) :4
sizeof(long) :4
sizeof(short) :2
sizeof(char) :1
sizeof(float) :4
sizeof(double):8

Here's where VxWorks5.5 of IDE tornado2.2 Testing in ( Compiler is SIMNTgnu):

sizeof(int)) :4
sizeof(long) :4
sizeof(short) :2
sizeof(char) :1
sizeof(float) :4
sizeof(double):8

You can see the two environments I tested ( compiler ) The results are the same :int occupy 4 Bytes .

This seems to be conclusive ,int Is to occupy 4 Bytes .

But I've heard before int It is not specified to occupy a few bytes , It's all up to the compiler . The compiler depends on the data model (Data model).

It can be seen that the constraints are satisfied :short and int Type at least 16 position ,long Type at least 32 position , also short Type length cannot exceed int type , and int Type cannot exceed long type . This means that the length of each type of variable is determined by the compiler , The current mainstream compiler is generally 32 Bit machine and 64 Bit machine int All types 4 Bytes ( for example ,GCC).

<> How many bytes does the pointer occupy

Let's talk about the pointer again .

The pointer is the address , The number of bytes occupied by a pointer has nothing to do with the language , It's about the addressing capability of the system , For example, it used to be 16 As address , The pointer is 2 Bytes , Now it's usually 32 Bit system , So it is 4 Bytes , in the future 64 position , Then 8 Bytes .

You can test it on your own computer .

I also tested two environments .
#include <stdio.h> int main(void) { int a=1; char b='a'; float c=1.0; void *p;
p=&a; printf("a Your address is :0x%x, The number of bytes is :%d\n",p,sizeof(p)); p=&b;
printf("b Your address is :0x%x, The number of bytes is :%d\n",p,sizeof(p)); p=&c;
printf("c Your address is :0x%x, The number of bytes is :%d\n",p,sizeof(p)); return 0; }
Here's where Dev-C++ 5.11 Test results in ( Compiler is gcc):

a Your address is :0x62fe14, The number of bytes is :8
b Your address is :0x62fe13, The number of bytes is :8
c Your address is :0x62fe0c, The number of bytes is :8

Here's where VxWorks5.5 of IDEtornado2.2 Testing in ( Compiler is SIMNTgnu):

( The compiler does not support Chinese , All Chinese have been deleted )

a address 0x3889238,bytes:4
b address 0x3889237,bytes:4
c address 0x3889230,bytes:4

You can see it on my computer Dev-C++ 5.11 upper , Pointer occupation 8 Bytes , The explanation is 64 Bit system , Addressing capability ( Address bus , So are address related registers 64 position ).

and VxWorks5.5 of IDE tornado2.2 in , Because it is in the embedded system , yes 32 Bit system , So the pointer is occupied 4 Bytes .

<> summary

The current operating system is generally 32 Bit sum 64 More bits , stay 32 Under operating system ,int occupy 4 Bytes , Pointer occupation 4 Bytes .64 Bit operating system ,int Also accounted for 4 Bytes , Pointer occupation 8 Bytes .

Technology
©2019-2020 Toolsou All rights reserved,
Redis Underlying data structure A person who dissuades others from learning computer , Are not good people win10 System computer C Where's the disc ,c disc users where? (win10c Disk not found users) Freshman c Language student management system ( lower ) hospital WIFI Which family is strong ? utilize Python Script unlimited spoof girlfriend computer C language program design —— Student management system Byte runout - Test development practice - One side cool meridian python Run code at specified time 5 Best style Linux Server system recommendation Anti anxiety life after naked resignation , I believe everything will have the best arrangement