Lecture 12Lecture 12
Version 1.0Version 1.0
Multidimensional ArraysMultidimensional Arrays
Passing Arrays to FuncionPassin...
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Multidimensional ArrayMultidimensional Array
 Arrays in C can have multiple ...
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Two Dimensional ArrayTwo Dimensional Array
 Arrays that require two subscrip...
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Two Dimensional ArrayTwo Dimensional Array
 When we say a 3X4 array, we decl...
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
Two Dimensional ArrayTwo Dimensional Array
 A multiple subscripted array can...
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Two Dimensional ArrayTwo Dimensional Array
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
The OutputThe Output
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
Two Dimensional ArraysTwo Dimensional Arrays
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
The OutputThe Output
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Remember!!Remember!!
 that while initializing a 2-D array it is necessaryth...
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Valid DeclarationValid Declaration
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Invalid DeclarationInvalid Declaration
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
Three Dimensional ArraysThree Dimensional Arrays
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Arrays to FunctionsPassing Arrays to Functions
 Array elements can ...
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Arrays to FunctionsPassing Arrays to Functions
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
OutputOutput
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Arrays to FunctionsPassing Arrays to Functions
18Rushdi Shams, Dept of CSE, KUET, Bangladesh
Function Prototype for functionsFunction Prototype for functions
taking arra...
19Rushdi Shams, Dept of CSE, KUET, Bangladesh
OutputOutput
Upcoming SlideShare
Loading in …5
×

C-12

204 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
204
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C-12

  1. 1. Lecture 12Lecture 12 Version 1.0Version 1.0 Multidimensional ArraysMultidimensional Arrays Passing Arrays to FuncionPassing Arrays to Funcion
  2. 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh Multidimensional ArrayMultidimensional Array  Arrays in C can have multiple subscriptsArrays in C can have multiple subscripts  A common use of multiple subscripted arrays isA common use of multiple subscripted arrays is to represent tables of valuesto represent tables of values  To identify a particular table element, we mustTo identify a particular table element, we must specify two subscripts: the first identifies thespecify two subscripts: the first identifies the row and the second identifies the columnrow and the second identifies the column
  3. 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh Two Dimensional ArrayTwo Dimensional Array  Arrays that require two subscripts to identify aArrays that require two subscripts to identify a particular element are called double subscriptedparticular element are called double subscripted arraysarrays  ANSI standard supports at least 12 subscriptsANSI standard supports at least 12 subscripts
  4. 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh Two Dimensional ArrayTwo Dimensional Array  When we say a 3X4 array, we declare it as follows-When we say a 3X4 array, we declare it as follows- int a [3][4];int a [3][4]; So, the first subscript denotes the row and the second subscriptSo, the first subscript denotes the row and the second subscript denotes the columndenotes the column
  5. 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh Two Dimensional ArrayTwo Dimensional Array  A multiple subscripted array can be initialized inA multiple subscripted array can be initialized in its declaration much like a single subscriptedits declaration much like a single subscripted arrayarray int b [2] [2] = {{1,2}, {3,4}};int b [2] [2] = {{1,2}, {3,4}};  in that case, 1 and 2 initialize b[0][0] and b[0][1]in that case, 1 and 2 initialize b[0][0] and b[0][1] and 3 and 4 initialize b[1][0] and b[1][1]and 3 and 4 initialize b[1][0] and b[1][1]
  6. 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Two Dimensional ArrayTwo Dimensional Array
  7. 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh The OutputThe Output
  8. 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh Two Dimensional ArraysTwo Dimensional Arrays
  9. 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh The OutputThe Output
  10. 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh Remember!!Remember!!  that while initializing a 2-D array it is necessarythat while initializing a 2-D array it is necessary to mention the second (column) dimension,to mention the second (column) dimension, whereas the first dimension (row) is optionalwhereas the first dimension (row) is optional
  11. 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh Valid DeclarationValid Declaration
  12. 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh Invalid DeclarationInvalid Declaration
  13. 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh Three Dimensional ArraysThree Dimensional Arrays
  14. 14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Arrays to FunctionsPassing Arrays to Functions  Array elements can be passed to a function byArray elements can be passed to a function by calling the function by value, or by referencecalling the function by value, or by reference  In the call by value we pass values of arrayIn the call by value we pass values of array elements to the functionelements to the function  in the call by reference we pass addresses ofin the call by reference we pass addresses of array elements to the functionarray elements to the function  As we did not see call by reference yet, we willAs we did not see call by reference yet, we will see that latersee that later
  15. 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Arrays to FunctionsPassing Arrays to Functions
  16. 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh OutputOutput
  17. 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Arrays to FunctionsPassing Arrays to Functions
  18. 18. 18Rushdi Shams, Dept of CSE, KUET, Bangladesh Function Prototype for functionsFunction Prototype for functions taking arrays as argumentstaking arrays as arguments  The function prototype for this will be-The function prototype for this will be- void print (int [ ][ ], int , int );void print (int [ ][ ], int , int );
  19. 19. 19Rushdi Shams, Dept of CSE, KUET, Bangladesh OutputOutput

×