+ 4

How much Bytes?

in java. if i declare integer variable it occupies 32 bytes. it does not matter what value i put in this variable. if i put 200 or 2, it does not effect variable's memory. if i am wrong plz correct me. and explain. sorry for bad English. edited. 32 bits not 32 bytes. thank u Michal, for correction

15th Jan 2018, 4:09 PM
sal sal
sal sal - avatar
3 odpowiedzi
+ 3
int is 32 bits, not 32 bytes it does not depend on the value in the variable it will be always 32 bits = 4 bytes
15th Jan 2018, 4:13 PM
michal
+ 4
(meta) Why? Because it's faster to retrieve aligned data (you know it's always a certain distance away) than arbitrarily-sized data (must do a full scan).
15th Jan 2018, 5:16 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Yes that is correct. In most languages a type of variable occupies a certain constant amount of bytes.
15th Jan 2018, 4:12 PM
spcan
spcan - avatar