Why do we need 2 bytes memory for storing a value as integer? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do we need 2 bytes memory for storing a value as integer?

In language c

16th Jan 2018, 12:44 PM
KALARI PRIYANKA
KALARI PRIYANKA - avatar
10 Answers
+ 2
Yes they can float will be 4 bytes because you need the extra bits to store decimal points. www.tutorialspoint.com/cprogramming/c_data_types.htm
16th Jan 2018, 1:21 PM
josh mizzi
josh mizzi - avatar
+ 1
I would assume that is just because you need more than one byte to store the the number of possible values an integer can have.
16th Jan 2018, 1:05 PM
josh mizzi
josh mizzi - avatar
+ 1
Because that is the most efficient. If you only need 2 byte, alicating10 is wasteful. Similarly if you need 2 alicating 1 us insufficient. Therefore you alicante 2.
16th Jan 2018, 1:09 PM
josh mizzi
josh mizzi - avatar
+ 1
I don't, you said it was. But normally data types have a set size. I am thus assuming that the size of int is 2bytes in C. I have just ch checked type int can either be 2 or 4 byte.
16th Jan 2018, 1:13 PM
josh mizzi
josh mizzi - avatar
+ 1
And I have answered. Because 1 byte was deemed insufficient by C's creators as it doesn't offer enough values. There is no other explanation.
16th Jan 2018, 1:17 PM
josh mizzi
josh mizzi - avatar
0
Then why can't we take 10bytes..why are we taking exactly 2bytes?
16th Jan 2018, 1:06 PM
KALARI PRIYANKA
KALARI PRIYANKA - avatar
0
how do you know that it is occupying 2 byte?
16th Jan 2018, 1:11 PM
KALARI PRIYANKA
KALARI PRIYANKA - avatar
0
Thnq for your reply!! I have asked why do we need! There must be some reason for 2byte memory allocation of integer values.
16th Jan 2018, 1:16 PM
KALARI PRIYANKA
KALARI PRIYANKA - avatar
0
I think this is not valid reason,sorry! because they can't assign different values for different datatypes like for example..float will occupy 4bytes.
16th Jan 2018, 1:20 PM
KALARI PRIYANKA
KALARI PRIYANKA - avatar
0
Oh thank you!!
16th Jan 2018, 4:46 PM
KALARI PRIYANKA
KALARI PRIYANKA - avatar