how does the pc know the size of int is 4. Is there any formula? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how does the pc know the size of int is 4. Is there any formula?

without using the help of pc ofcourse

7th Jun 2019, 4:19 PM
Amod T V
Amod T V - avatar
7 Answers
+ 1
Well for c and c++, the compiler is platform dependant, in order to make the language platform independent. This means you need to write a separate compiler for x86, amd64, arm, etc. The compiler will have the base type sizes (int) hard coded into it. Derived types like size_t will be converted to real types (unsigned int, etc), structs and unions will be calculated based on the types they contain.
7th Jun 2019, 11:58 PM
Jared Bird
Jared Bird - avatar
+ 1
ok so is it inbuilt??
8th Jun 2019, 12:31 AM
Amod T V
Amod T V - avatar
0
please explain
7th Jun 2019, 4:21 PM
Cat Sauce
Cat Sauce - avatar
0
when you type sizeof(int) in pc it will give 4
7th Jun 2019, 4:24 PM
Amod T V
Amod T V - avatar
0
how does it do it??
7th Jun 2019, 4:24 PM
Amod T V
Amod T V - avatar
0
This depends on your processor as well as compiler.If you have 16 bit computer then sizeof (int)=2 and if you have 32 bit computer then sizeof(int)=4.Hope you got😊
7th Jun 2019, 5:32 PM
Pranjal Dahal
Pranjal Dahal - avatar
0
8th Jun 2019, 1:11 AM
Jared Bird
Jared Bird - avatar