Advertisement

Responsive Advertisement

IV.1. Arrays Declaration, IV.2. Arrays Elements

 


IV.1. Arrays Declaration

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows.

type arrayName [ arraySize ];

This is called a single-dimensional array. The arraySize must be an integer constant greater than zero and type can be any valid C data type. For example, to declare a 10-element array called balance of type double, use this statement 


IV.2. Arrays 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. For example .

double salary = balance[9];

The above statement will take the 10th element from the array and assign the value to salary variable. The following example Shows how to use all the three above mentioned concepts viz. declaration, assignment, and accessing arrays .





Post a Comment

0 Comments