ProgrammerGuide.Net | Step by Step Programmer Guide

C – Array


So far we have used only the fundamental data type, namely char, int, float, double and variations of int and double and variation s of int and double. although these types are very useful, they are constrained by the fact that a variable of these type can only store only one value at any given time. Therefore, they can be used to only handle limited amounts of data. In many applications, however, we need to handle to large volume only to handle this. To process such large amounts of data, we need a powerful data type that would facilitate efficient storing, accessing and manipulation of data, we need a powerful data types that would facilitate  supports a derived data types known as array that can be used for such applications.

An array is fixed-size sequenced collection of elements of the some data type. It is simply a grouping of like-type data. In its simplest form, an array can be used to represent a list of numbers, or a list of names. Some examples where are concept of an array can be used:

1. List of temperatures recorded every hour in a day, or a month, or a year
2. List of employees in an organization.
3. List of products and their cost sold by a store.
4. Table of daily rainfall data.
and so on.

Since an array provides a convenient structure for representing data, it is classified as one of the data structure in C. Other data structure include structures, lists, queues an trees. We can use array to represent not only simple list of values but also tables of data in two or three or more dimensions. in this chapter, we introduce the concept of an array and discuss how to use  its create and apply the following type of array.

1. One-dimensional arrays
2. two-dimensional arrays
3. Multidimensional arrays

Data Structures.

A.Data Types
a. Derived Types
             1. Arrays
             2. Functions
             3. Pointers
b. Fundamental Types
             1. Integral Types
             2. Float Types
             3. Character Types
c. User-defined Types
              1. Structures
              2. Unions
              3. Enumerations

In addition to array an structures, C supports creation and manipulation of the following data structures:

1. Linked Lists
2. Stacks
3. Queues
4. Trees

Like other languages, C uses arrays as a way of describing a collection of variables with identical properties. The group has a single name for all of the members, with the individual members being selected by an index. Here’s an array being declared:

The name of the array is ar and its members are accessed as ar[0] through to ar[99] inclusive, as Figure 5.1 shows.

array[0]array[1] array[99]

One important point about array declarations is that they don’t permit the use of varying subscripts. The numbers given must be constant expressions which can be evaluated at compile time, not run time. For example, this function incorrectly tries to use its argument in the size of an array declaration:

f(int x)
char var_sized_array[x];

It’s forbidden because the value of x is unknown when the program is compiled; it’s a run-time, not a compile-time, value.To tell the truth, it would be easy to  arrays whose first dimension is variable, but neither Old C nor the Standard permits it, although we do know of one Very Old C compiler that used to do it.That’s all very well, but does it really matter in practice? Not much it’s true; but it is interesting to note that in terms of actual machine storage layout the rightmost subscript ‘varies fastest’. This has an impact when arrays are accessed via pointers. Otherwise, they can be used just as would be expected.

Please click here for related products on Amazon!


Add comment

Want to Check Celebrities News?