ARRAYS

Declaring Arrays

the type of the elements

number of elements required

single-dimension array.

arraySize must be an integer constant greater than zero

type can be any valid C++ data type

EX:to declare a 10-element array called balance of type double

Subtopic

Accessing Array Elements

An element is accessed by indexing the array name.

This is done by placing the index of the element within square brackets after the name of the array.

Initializing Arrays

You can initialize C++ array elements either one by one or using a single statement

Exp:double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};

The number of values between braces { } can not be larger than the number of elements

array just big enough to hold the initialization is created

double balance[] = {1000.0, 2.0, 3.4, 17.0, 50.0};

C++ Arrays in Detail

Arrays are important to C++ and should need lots of more detail

Multi-dimensional arrays

C++ supports multidimensional arrays. The simplest form of the multidimensional array is the two-dimensional array.

Pointer to an array

You can generate a pointer to the first element of an array by simply specifying the array name, without any index.

Passing arrays to functions

You can pass to the function a pointer to an array by specifying the array's name without an index.

Return array from functions

C++ allows a function to return an array.

HADI&FADZIL