An array must be defined just like any other object. The definition includes the array name and the type and number of array elements.
type name[count]; // Array nameIn the above syntax description, count is an integral constant or integral expression containing only constants.
float arr[10]; // Array arrThis statement defines the array arr with 10 elements of float type. The object arr itself is of a derived type, an “array of float elements” or “float array.”
//computes the total and average of five numbers #include <iostream.h> float data[5]; // data to average and total float total; // the total of the data items float average; // average of the items main () { data[0] = 34.0; data[1] = 27.0; data[2] = 46.5; data[3] = 82.0; data[4] = 22.0; total = data[0] + data[1] + data[2] + data[3] + data[4]; average = total / 5.0; cout << "Total "<< total << " Average " << average << '\n'; return (0); }
Total 211.5 Average 42.3