Explain declaration, initialization of One dimensional and Two dimensional arrays.

Data Structures and Algorithms

Explanation

1286
0

==> One Dimensional Array---

               Declaration::

                      Syntax: data_type array_name[array_size];

                                   where, data_type can be int, float or char.

                                   array_name is the name of the array.

                                   array_size indicates number of elements in the array.

                                   For ex: int age[5];

             Initialization::

                          Syntax: data_type array_name[array_size]={v1,v2,v3};

                                       where, v1, v2, v3 are the values

                                       For ex: int age[5]={2,4,34,25,18};

==> Two Dimensional Array----

             Declaration::

                            Syntax: data_type array_name[array_size][array_size];

                                          where, first index shows the row number of the element and

                                                         second index shows the coulmn number of the element

            Initialisation::

                             Syntax: data_type array_name[array_size][array_size]={V1,V2,V3,.....Vn};

                                           where, V1, V2, V3,......,Vn are the values

                             For ex: int matrix[2][3]={2,4,56,3,6};