Arrays PDF
Arrays PDF
• When we put 10 integers into an array, arr, the index of first element
in the array will be 0, second element will be 1, and so on, the last
element has index 9.
• Array elements can be read and printed using loops, hence reducing
the size of code.
• The array’s name is a symbolic reference for address to the first byte
of the array. Wherever we use array name, we are actually referring
to first byte of the array.
• The index represents an offset from beginning of the array to the
element being referred.
• Using starting byte and an index, C can also access an element at a
given index using following formula:
element_address=array_address + (sizeof(element)*index))
Let starting address be 10,000, stores integers, and index be 3, then
Element_address=10,000 + 4*3 = 10,012.
Arrays – Storing Values in an Array
• The arrays discussed so far are known as One-dimensional arrays are elements are
arranged linearly in only one direction.
• Many applications require data be arranged in more than one direction, such as a
table, which is a collection of rows and columns.
• This is represented as an array that consists of rows and columns, known as Two-
dimensional array.
• It can be viewed as an array of arrays.
Two-dimensional Arrays