elibraryportal Logo

What is an Array in C

An array is a collection of same data types that is store value in single variable.

Advantage of Array

1) Code Optimization: Less code for access the data.

2) Ease of traversing: Easily we can retrieve the elements of an array .

3) Ease for sorting: To sort the elements you can use few lines of code only.

4) Random Access: We can access any element randomly using the array.

Disadvantage of C Array

Fixed Size: We are define at the time of declaration of the array, we can't exceed the limit. So, it doesn't grow the size dynamically like LinkedList .

Declaration of Array

We are declare an array in the following way.

Now, let see the example to declare the array.

Initialization of Array

Example1

Output

10
20
30
35
45

Array Declaration with Initialization

We can initialize the an array at the time of declaration.

if they are not define the size So it may also be written as the following code.

Example2

Output

20
30
40
50
60

Sorting Example an array

Output

Printing Sorted Element List ...                                                                
101                                                                                             
78                                                                                              
44                                                                                              
34                                                                                              
23                                                                                              
23                                                                                              
12                                                                                              
10                                                                                              
9                                                                                               
7   
Next Topic