Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am too confused by your question. So, I am answering assuming that you really meant <strong>byte</strong> when you meant <strong>bit</strong> in the above questions.</p> <blockquote> <p>First.Why char hold 4 bit memory(should it only take one?)?</p> </blockquote> <p>Nothing in the result shows that char is holding a 4 bytes in the memory. What you actually printed are the addresses at which the variables are stored. Not the sizes. The compiler assigning a 4-byte word to for char doesn't necessarily mean that char is occupying 4 bytes. Char only occupies 1 byte of the assigned 4 byte word and the remaining 3 bytes are padded with zeroes. If you are talking about the char pointer, then as you are aware, the pointer stores the address of the char variable it is pointing to. And this address is a unsigned integer which is 4 bytes in size.</p> <p>To get the size of the variables use <strong>sizeof</strong> operator</p> <blockquote> <p>And . Why float only take 4 bit memory? I think it will transform to double auto ! Ant double take 8 bit!</p> </blockquote> <p>The size of Float is 4-bytes (on 32-bit systems). So the compiler assigned 4 bytes. The size of double is always twice that of float. So the compiler assigned a 8 byte address space to store the value. I don't understand why you think that float will be transformed to double. The program doesn't require any such auto conversion.</p> <p>The compiler assigns addresses in 4-byte words because the computer accesses memory one word at a time for efficiency. The general rule is that this 'access length' (which is 4 bytes in this case) must be at least the size of the lowest size primitive data type (which is char - 1 byte length)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload