Array: It Is a Derived Data Type

Total Page:16

File Type:pdf, Size:1020Kb

Array: It Is a Derived Data Type

Array: It is a derived data type. It is a group of elements of the same type referenced by a single name. An array is a data structure which allows a collective name to be given to a group of elements of all of which have the same data type. An array consists of a series of consecutive data storage locations. An individual element of an array is identified by its own unique index or subscript

Need for Arrays- Arrays help to make a program simple, easy to code and understand.

Single(1-d array): An array whose element are specified by a single subscript. It is a collection of finite, homogeneous element.

Multidimensional array: An array that has more than one subscript is known as multidimensional array.

Array Declaration: data-type array_name[size] , const int size; float x[size]

Array Initialization: int list[5]={10,20,30,40,50} or int list[]={10,20,30,40,50}, int a[3]={1,2,3,4,5}- too many intializers error, int b[4]={1,2} the rest b[2] & b[3] will have 0’s in it.

Unsized Array: C++ allows one to skip declaring size of an array in an array initialization statement. It automatically creates an array long enough to hold all the intializers present. This is known as unsized array. It automatically calculates the dimensions of unsized arrays. E.g. int num[]={1,2,3} it will calculate the size of an array as 3 data elements occupying 2 bytes each.

Recommended publications