(If so I'm guessing memory positions are further broken down into chunks of bytes) |
Two things to note.
First, a byte is not necessarily eight bits long. A byte is merely the smallest unit of memory that is addressable by the CPU. Therefore, by definition a memory position contains always exactly one byte, although the number of bits it contains depends on the architecture (it could be 1, 8, 12, etc.).
Second, a memory position is not further divisible, except at the electronics level. All you can do with a memory position from software is read it entirely or overwrite it entirely.
lets say first is at memory address 1000 and takes space at that memory address up until and including 1003,so will the char second be at the same memory address as first? |
If two variables were to exist at "the same" memory address then their memory regions would overlap, then when you wrote to one of them you'd be indirectly changing the value of the other.
will the char second be at the same memory address as first? but just as another position in that memory(1004)? |
These two suppositions are contradictory. If two variables are at the same address (
&first == &second
) then they occupy the same memory positions. If they occupy different memory positions then they have different addresses.
Case 1 - first and second at same address (1000)
Memory position 1000: [first byte of 'first'] [second] <-- these two values are the same
Memory position 1001: [second byte of 'first']
Memory position 1002: [third byte of 'first']
Memory position 1003: [fourth byte of 'first']
Case 2 - first and second at different addresses (1000 and 1010)
Memory position 1000: [first byte of 'first']
Memory position 1001: [second byte of 'first']
Memory position 1002: [third byte of 'first']
Memory position 1003: [fourth byte of 'first']
(Gap)
Memory position 1010: [second]
or will it be in a totally separate address(if so this seems kind of wasteful) |
Why do you think this would be wasteful? Are you perhaps confusing the ideas of "address" and "address space"? An address space is something entirely unrelated to this discussion; it has to do with how the operating system manages virtual memory between different processes.
EDIT:
but the thing that is just confusing me is that address 1000 which holds the first 8 bits of the integer is just that it is 8 bits in size(the amount the address at that point) can store, so people are saying that memory addresses are 32 bits in size or I should say can store 32 bits of data inside of them but from what I can see is they are capable of storing a byte or 8 bits? |
Think back to the hotel example. A room number may be seven digits long, but this tells you nothing about how many people can fit in a hotel room.
Likewise, an address may be 32 bits long, but again this tells you nothing about how many bits can be stored at the memory position referenced by a given address.