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.

 
by Dinesh Thakur Category: Array

In the HSC examination, there are six subjects each having a maximum of 100 marks. To pass the examination, a student has to score at least 35 marks in each subject. If a student passes, total marks and percentage marks are calculated and a class is awarded based on the percentage marks (perce)as follows:

 
by Dinesh Thakur Category: Array

C language permits the use of multidimensional arrays. It is easy to visualize arrays up to three dimensions. However, we may have difficulty in visualizing a four, five or in general, an n-dimensional array.

 
by Dinesh Thakur Category: Array

When we declare a pointer, it does not point to any specific variable. We must initialize it to point to the desired variable. This is achieved by assigning the address of that variable to the pointer variable, as shown below.

 
by Dinesh Thakur Category: Array

Each element of an array is a variable of the type declared for the array. Thus, if an array is declared as int Array [n],all its n elements are of type int, and all the operations that can be done on variables of type int may be carried out on the elements of this array. The same holds for arrays of types float, double, and char. In Program integer array elements are subjected to arithmetic operations.

 
by Dinesh Thakur Category: Array

In case of large arrays, the method of comparing every array element with key as described above is rather inefficient. However, if an array is a sorted one, the search process can be considerably shortened by using binary search method. For the application of binary search the array should be first sorted.

 
by Dinesh Thakur Category: Array

We can pass an array (one-, two- or multidimensional) as an argument to a function. The C language allows us to define functions that have one or more arrays as parameters. These parameters can be of different types and sizes. Moreover, we can mix scalar and array parameters. A function that uses a single one-dimensional array as a parameter can be defined as shown below.

 
by Dinesh Thakur Category: Array

The procedure of passing more than one arrays to a function is similar to the case of passing a single array. This is illustrated in Program.

 

Page 13 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.