by Dinesh Thakur Category: Array

Any operation on an array has to be carried out element by element. It cannot be performed on the array as a whole. Therefore, in swapping also, an element of one array is swapped with an element of another array. The two may not have the same index value if you are not dealing with vectors and matrices.

 
by Dinesh Thakur Category: Array

The amount of memory an array can consume depends on the data type of an array. In DOS environment, the amount of memory an array can consume depends on the current memory model (i.e. Tiny, Small, Large, Huge, etc.).



 
by Dinesh Thakur Category: Array

Pointers and Arrays : Data objects in an array can be referenced through pointers instead of using array subscripts. The data type of such a pointer is referred to as "pointer to array of type". The array name itself behaves like a pointer, so there are several alternative methods to accessing array elements. For example :



 
by Dinesh Thakur Category: Array

Initializing Arrays : Arrays are initialized with a brace-enclosed list of constant expressions. A list of initializers for an incomplete array declaration completes the array's type and completely defines the array size.

 
by Dinesh Thakur Category: Array

The maximum or minimum value may be determined by comparing the values of array elements. Let us assume that the maximum value is represented by 'max'. The value of the first element of the array is assigned to max.

 
by Dinesh Thakur Category: Array

When a program containing an array of size n is compiled, the compiler allocates n blocks of memory for the array for storing the values of its elements. The size of each block depends on the data type of the array. For example, for the array AR [ ] defined below, five blocks of memory are allocated and each block is of the size of the memory block for an integer (i.e., 4 bytes on a 32-bit system).



 
by Dinesh Thakur Category: Array

Array Declaration

Every array is given a name. The rules for naming arrays are the same as those used for variable names. As with scalar variables, an array must be declared before it is used. The declaration of a one-dimensional array takes the following form:

 
by Dinesh Thakur Category: Array

Declaring Arrays : Arrays are declared with the bracket punctuators [ ], as shown in the following syntax :

 
by Dinesh Thakur Category: Array

A two-dimensional array (commonly called a matrix) consists of elements of the same type arranged in rows and columns. The rows and columns of a matrix are numbered starting from 0. Thus, for an array of size rows x cols, the row subscripts are in the range 0 to rows - 1 and the column subscripts are in the range 0 to cols - 1.

 
by Dinesh Thakur Category: Array

Searching an array for a value is the most common occurrence in programming as well as in real life. Often it is required to search a name in a list of names or search a roll number in a list of roll numbers.

 
by Dinesh Thakur Category: Array
 
by Dinesh Thakur Category: Array

An array is similar to a list in which the objects are of the same type and stored in sequential memory blocks; this is the only relationship between the elements of an array. The input/output of values of elements of an array cannot be done as whole of array, but is carried out element by element. This may be done by accessing each element by its index value. Therefore, for large arrays, either a for loop or a while loop may be used for accessing each element for its input/output. For example, if elements of an array Array [4] having 4 elements are to be processed for input /output by user of a program, the program code may be written as follows:

 
by Dinesh Thakur Category: Array

Suppose, we want to sort an array in ascending order. The elements with higher values will move back, while elements with smaller values will move to the front; the smallest element will become the 0th element and the largest will be placed at the end. The mechanism of sorting is explained below.

 

Page 12 of 16



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.