How elements are stored in an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • glepatron01
    New Member
    • Jul 2007
    • 1

    #1

    How elements are stored in an array

    can i ask how are elements of an array stored in an memory?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    It is required that the elments be contiguous in memory. Otherwise, pointer calculations are not possible.

    All arrays are one-dimensional.

    int array[4]; //4 elements each element an int

    is stored

    0 1 2 3

    int array[4][2]; //4 elements with each element an array of 2 int

    0 1 0 1 0 1 0 1
    0 1 2 3

    The first index is the number of elements. Any other indexes just describe the element.

    Comment

    Working...