memory management - data type storage in C -


i want understand how declaring variable char saves memory declaring int or short. know fact declaring char reserves 1 byte in memory while 2 or 4 bytes reserved int. now, suppose in 16 bit processor, variable char stored @ location 0xabcd. since 16 bit processor, 1 byte or 8 bits of 16 bits @ address 0xabcd reserved char. int variable stored @ location 0xbcde, accordingly reserve 16 bits of 16 bits available @ location 0xbcde. want know happens 8 bits @ location 0xabcd left on after reserving memory char variable considering fact @ 1 memory location 1 variable can stored.

memory addresses not work "variables". can not store 8 or 16 bits, can only , exclusively store exactly 8 bits (one single byte). (a)

when int gets stored "at" address, takes more space -- not "in" same address, flowing on in next memory addresses, following "the" memory address. thus, if store char @ 0xabcd, compiler knows it's safe assume next value can stored @ 0xabce. if store 16-bit short @ 0xabcd, compiler knows data gets stored in 0xabcd and 0xabce.(b)


(a) sake of clarity. there configurations single memory unit can hold more or less bits (historically, 8th bit meant error checking, , 1 store 7 significant bits of data in each location).

(b) again, sake of clarity. compiler may decide use 4, or 8 bytes of memory space each type of char, short, , int. because reading , writing "native" size value memory may faster "odd" sizes. "native" size of data 1 cpu designed specifically for.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -