Lec c7 - More than one Dimension Two dimensional arrays...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
More than one Dimension Two dimensional arrays also called as matrix Declaration: type variable_name[row_size][column_size]; row_size –>Number of rows in matrix column_size –> Number of columns in matrix Examples: int number[4][3]; /* 12 elements */ float number[3][2]; /* 6 elements */ char name[10][20]; /* 200 chars */
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Initialization of a 2-D Array int a[2][3]={1,2,3,4,5,6}; int a[2][3]={{1,2,3}, {4,5,6}}; int a[][3]={{1,2,3}, {4,5,6}} int a[2][3]={0} How values will be assigned in each case?? Following initializations are not allowed int a[3][]={2,4,6,8,10,12}; int a[][]={2,4,6,8,10,12}; Note: If the first bracket pair is empty, then compiler takes the size from the number of inner brace pairs
Background image of page 2
Initialization of a 2-D Array The following fragment of code initializes the array (arr[rows][columns])at runtime: for (i=0;i<rows;i++) for (j=0;j<columns;j++) scanf (“%d”,&arr[i][j]); Q. Can we interchange “rows” and “columns” in the above code fragment ???
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/14/2010 for the course CS SS ZG653 taught by Professor Shanta during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 11

Lec c7 - More than one Dimension Two dimensional arrays...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online