Wednesday, November 2, 2011

Introduction to C++ Arrays

Understanding C++ Arrays


C++ Arrays help us understand how to store large data. C++ arrays consists of set of objects (called its elements), all of which are of the same type and are arranged contiguously in memory. understanding C++ Arrays provide you with a convenient way to manipulate storage of large amounts of data from within programs. C++ Arrays allow for setting aside a group of memory locations which we can then manipulate as a single entity, at the same time enabling us direct access to any individual component.

C++ Array elements are grouped under one symbolic name or identifier. All C++ array elements are positioned next to one another in the memory and are indexed in the order they are arranged beginning from position zero. The index of each C++ array element is used to access that element. The number of elements in a C++ array is called its dimension. The dimension of a C++ array is fixed and predetermined, it cannot be changed during program execution.

A C++ array is declared as follows:
 
DataType ArrayIdentifier [NumberOfElements]

Suppose we want to store the grades of 10 students in a class. We can declare and initialize C++ array elements of grades array as follows;

int grades[10]={35,60,55,50,65,80,70,75,45,85}

Read the whole Chapter on C++ Arrays

No comments:

Post a Comment