![](smile.gif)
How are arrays implemented?
Hi!
If you have a big array of something
(whateverType MyArray[100000])
then we all know that in order to get the n:th element we just write ex = MyArray[n];
okej, so far so good. My question is:
hpw is thsi implemented in most compilers? Is it done with some sort of pointer arithmetics or is it really a constant operation to get an element from an array??
just curious
--Spencer
![](smile.gif)
--Spencer"All in accordance with the prophecy..."
compiler does something like this
ex = *(MyArray + n*sizeof(whateverType));
maybe ?
gets the starting address of the array
calculates the byte offset and adds it on
then dereferences it to get what is there
"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
ex = *(MyArray + n*sizeof(whateverType));
maybe ?
gets the starting address of the array
calculates the byte offset and adds it on
then dereferences it to get what is there
"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement