As helios said, perhaps we should say memory
position instead.
It doesn't matter how big the
int datatype is itself -- it can still start at memory position of 1000.
Let's forget about specific data types. We have a computer, and it has a
lot of data loaded on it. We need to access that data. Each piece of data that we want starts at a certain position in memory.
If we're in a game, and the game has
one million unique trees in it, we need a way to access each tree. To do this, we access each tree at an position in memory.
If we only had 8 bits to work with in this game, we could only have 256 trees accessible. We could only address trees 1 to 256. There would be no way to access tree #257, because our memory addresses could only go up to 256.
To access all 1 million trees, we would need our memory address to be at least 20 bits long, because 2
20 is greater than one million.
Does that part make sense, at least on its own? If not, don't read the rest of this post.
___________________________________________
Now, let's say we have the million trees, and then we also have a player's name. We already used the first million memory positions to store our tree data. So, we can store the player's name starting at position 1,000,001.
Now, whether my name is "Bill" or "Nebuchadnezzar", I can still say that the player's name is stored starting at position 1,000,001. But "Bill" would take up 4 units, while "Nebuchadnezzar" would take up 14 units.
address 1,000,001 : B
address 1,000,002 : i
address 1,000,003 : l
address 1,000,004 : l
___________________________________________
Going back to actual data types, let's say I want to store a
2-byte int.
A 2-byte int might look like this:
1100 0011 1010 0111.
We're going to store this at the memory position 2 million, because we're already using the lower addresses for other objects. Since we need to address at least 2 million positions, we need to store this address using at least 21-bits (because 2
20 > 2 million) -- regardless of how big an int is.
Now, since sizeof(my 2-byte int) == 2, that means 2 positions in memory will "belong" to the int.
Memory position 2,000,000 will hold "1100 0011".
Memory position 2,000,001 will hold "1010 0111".
Different memory positions are
addressable in byte-sized increments, but that doesn't mean that a memory address itself is a byte (in our case, the memory address itself needed to be at least 20 bits to hold 2 million+ possible addresses).
___________________________________________
as you said the address of the first char &arr[0] will be 1000 and [1] will be 1001, so this means the memory address 1000 is 8 bits |
No, the memory address 1000 -- i.e. the actual number needed to say "this object is at the following position" -- is not 8-bits. (1000 couldn't even fit into 8 bits).
The address 1000 (which would incidentally need at least 10 bits to represent), only refers to the
starting position of the data.