Arrays in C Programming Language

It is a collection of similar ( same data type) data items.

Arrays in C is a classification of data structure that can store a fixed-size sequential collection of elements of the same type. An array is utilized to store a collection of data, however, it is often more useful to consider of an array as a collection of variables of the same type.

HOW MANY TYPES OF ARRAYS ARE THERE?

There are two types of Array:

1. One dimensional Array

2.Multidimensional Array

 

DECLARATION OF ARRAY

Arrays in C

To declare an array in C, a programmer defines the type of the elements and the number of elements needed by an array.

1. ONE DIMENSIONAL ARRAY

Declaration in C :

data_type arr_name [arr_size];

Initialization in C:

data_type arr_name[arr_size]=(value1, value2, value3,….);

Accessing in C:

array_name[index];

2. MULTIDIMENSIONAL ARRAY

Declaration in C :

data_type arr_name [num_of_rows][num_of_column];

Initialization in C:

data_type arr_name[arr_size]=(value1, value2, value3,….);

Accusing in C:

array_name[index];

WHY ARRAYS?

  • Less amount of code
  • Easy access to elements
  • Easy to implement algorithms
  • Random Access

We can access any element of the array in O(1) time complexity.

NOTE: We cannot use negative indexes

Leave a Reply

Shopping cart