Advertisement

How are arrays implemented?

Started by April 06, 2001 10:06 AM
0 comments, last by Spencer 23 years, 10 months ago
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
--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

This topic is closed to new replies.

Advertisement