{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Arrays - EECE 230 S Karaki 4 Arrays 1 4 ARRAYS 4.1...

This preview shows pages 1–5. Sign up to view the full content.

EECE 230 – S. Karaki 4. Arrays 1 Name of array (Note that all elements of this array have the same name, C) Position number of element within array C 4. ARRAYS 4.1 Introduction Arrays are data structures consisting of several data items of the same type. 4.2 Arrays An array is a consecutive group of memory locations that all have the same name and the same type. To refer to a particular location or element in the array, we specify the name of the array and the position number of the particular element in the array, as shown in the figure below. C[0] -45 C[1] 6 C[2] 0 C[3] 72 C[4] 1543 C[5] -89 C[6] 0 C[7] 62 C[8] -3 C[9] 1 C[10] 6453 C[11] 78 The position number contained within square brackets is more formally called a subscript . A subscript must be an integer or an integer expression. For example, if we assume that variable a is equal to 5 and that variable b is equal to 6 , then the following statement adds 2 to array element C[11] C[a +b] + = 2; To divide the value of the seventh element of array C by 2 and assign the result to the variable x , we would write: x = C[6] / 2; The brackets used to enclose the subscript of an array are actually considered to be an operator in C++. Brackets have the same level of precedence as parentheses.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document