Detailed Discription of 2-D Array of C Language[Tutorial]

Multi-Dimensional Array

Multidemensional Arrays:

If the number of subscripts is more than one, then such Arrays are called Multi-dimensional Arrays that is we can say 2-D Array , 3-D Array and so on. The dimensionality is understood from the number of pairs of square brackets placed after the Array name.

Example: 
  1. Array 1[ ]  => 1-D Array
  2. Array 2[ ][ ]  => 2-D Array
  3. Array 3[ ][ ][ ]  => 3-D Array

                                                    Two-Dimensional Arrays:                                               


Two-Dimensional Array

2-D Array generally referred to as a Matrix, of some Rows and some Columns. It is an Ordered tabel of Homogeneous elements. It is also called as a two-subscripted variable.


                                                              Declaration:                                                           

The syntax of declaring a two-dimensional Array in C as follow:


   datatype Array_name[rows] [columns] ;  

where
rows => number of elements to be processed under subscript 1
columns => number of elements to be processed under subscript 2

Example:
  • int Marks[3] [5];
Marks is a 2-D Array of 3 rows and 5 columns.
  • char Page[25] [80];
Page is a 2-D Array of 25 rows and 80 columns.


                                                   Initialization of 2-D Array:                                               

Like, initialization of 1-D Array elements, 2-D Array elements can also be initialized at the time of declaration. The syntax for a 2-D Array initialization is as follows:


   data_type Array_name[size1] [size2] = {e1 , e2 ,....en};  

where
e1 , e2 , ......en => initial values to be assigned to n elements of Array.

Example:
  • int Matrix[3][3] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9};
Then, First 9 elements of the matrix will be

Matrix[0][0] = 1                  Matrix[0][1] = 2                        Matrix[0][2] = 3
Matrix[1][0] = 4                  Matrix[1][1] = 5                        Matrix[1][2] = 6
Matrix[2][0] = 7                  Matrix[2][1] = 8                        Matrix[2][2] = 9


                                                   Points to be Remember:                                                   
  • If the number of elements to be assigned are less than the total number of elements, then all the remaning elements are Automatically assigned to zero.
Ex:                                                  int ab[2][2] = {2 , 4 , 6};

Here, ab is a 2-D Array of  2*2  elements of type int. But, only the first 3 elements are initialized. The fourth element is then automatically set to zero i.e

                                              ab[0][0] = 2      ab[0][1] = 4
                                              ab[1][0] = 6      ab[1][1] = 0
  • If the number of elements to be assigned are more than the the total number of elemens that 2-D Array contained then there will be a compilation error.
  • One to One mapping is preserved i.e the first set of initial values is assigned to the first Row elements and the second set of initial values is assigned to the second Row elements an so on.
Ex:                                         int ary[2][2] = { {1,2} , {3,4} };

Here, the inner set {1,2} is taken for assigning values 1 and 2 to the first Row elements of an Array ary i.e
                                                ary[0][0] = 1        ary[0][1] = 2

Similarly, the other set {3,4} is taken for assigning values 3 and 4 to the second Row elements of an Array ary i.e
                                                ary[1][0] = 3        ary[1][1] = 4



                                                                   That's All

0 Response to "Detailed Discription of 2-D Array of C Language[Tutorial]"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag