SlideShare une entreprise Scribd logo
1  sur  19
Lecture 12Lecture 12
Version 1.0Version 1.0
Multidimensional ArraysMultidimensional Arrays
Passing Arrays to FuncionPassing Arrays to Funcion
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
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
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
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]
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 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
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 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
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 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 );
19Rushdi Shams, Dept of CSE, KUET, Bangladesh
OutputOutput

Contenu connexe

Tendances

02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
Tareq Hasan
 

Tendances (20)

02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
7. Rest parameters | ES6 | JavaScript
7. Rest parameters | ES6 | JavaScript7. Rest parameters | ES6 | JavaScript
7. Rest parameters | ES6 | JavaScript
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
8. Spread Syntax | ES6 | JavaScript
8. Spread Syntax | ES6 | JavaScript8. Spread Syntax | ES6 | JavaScript
8. Spread Syntax | ES6 | JavaScript
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
NaBL: A Meta-Language for Declarative Name Binding and Scope Rules
NaBL: A Meta-Language for Declarative Name Binding  and Scope RulesNaBL: A Meta-Language for Declarative Name Binding  and Scope Rules
NaBL: A Meta-Language for Declarative Name Binding and Scope Rules
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
 
1. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES61. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES6
 
Strings in c
Strings in cStrings in c
Strings in c
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
 
String.ppt
String.pptString.ppt
String.ppt
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Assembly language
Assembly languageAssembly language
Assembly language
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Assembly Language String Chapter
Assembly Language String Chapter Assembly Language String Chapter
Assembly Language String Chapter
 
Modern C++
Modern C++Modern C++
Modern C++
 

En vedette

L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
Rushdi Shams
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and Arrays
Rushdi Shams
 
Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
Rushdi Shams
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory Concept
Rushdi Shams
 
Lec 23. Files (Part II)
Lec 23. Files (Part II)Lec 23. Files (Part II)
Lec 23. Files (Part II)
Rushdi Shams
 
L14 l15 Object Oriented DBMS
L14 l15  Object Oriented DBMSL14 l15  Object Oriented DBMS
L14 l15 Object Oriented DBMS
Rushdi Shams
 
L4 domain integrity
L4  domain integrityL4  domain integrity
L4 domain integrity
Rushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
Rushdi Shams
 

En vedette (9)

L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and Arrays
 
Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory Concept
 
Lec 23. Files (Part II)
Lec 23. Files (Part II)Lec 23. Files (Part II)
Lec 23. Files (Part II)
 
L14 l15 Object Oriented DBMS
L14 l15  Object Oriented DBMSL14 l15  Object Oriented DBMS
L14 l15 Object Oriented DBMS
 
L4 domain integrity
L4  domain integrityL4  domain integrity
L4 domain integrity
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L3 defense
L3  defenseL3  defense
L3 defense
 

Similaire à Lec 12. Multidimensional Arrays / Passing Arrays to Functions

Lec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysLec 11. One Dimensional Arrays
Lec 11. One Dimensional Arrays
Rushdi Shams
 
Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
Rushdi Shams
 
Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuples
Abed Bukhari
 
Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by Reference
Rushdi Shams
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
dplunkett
 

Similaire à Lec 12. Multidimensional Arrays / Passing Arrays to Functions (20)

Lec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysLec 11. One Dimensional Arrays
Lec 11. One Dimensional Arrays
 
Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
 
Java R20 - UNIT-3.docx
Java R20 - UNIT-3.docxJava R20 - UNIT-3.docx
Java R20 - UNIT-3.docx
 
Array String - Web Programming
Array String - Web ProgrammingArray String - Web Programming
Array String - Web Programming
 
Unit 2
Unit 2Unit 2
Unit 2
 
Learn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & ArraysLearn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & Arrays
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuples
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by Reference
 
arrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdfarrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdf
 
Plc (1)
Plc (1)Plc (1)
Plc (1)
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
2ds
2ds2ds
2ds
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Lec 16. Strings
Lec 16. StringsLec 16. Strings
Lec 16. Strings
 
Introduction to System verilog
Introduction to System verilog Introduction to System verilog
Introduction to System verilog
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 

Plus de Rushdi Shams

Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
Rushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
Rushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
Rushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
Rushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
Rushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
Rushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
Rushdi Shams
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
Rushdi Shams
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineering
Rushdi Shams
 

Plus de Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineering
 

Dernier

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Dernier (20)

Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Pharmaceutical Biotechnology VI semester.pdf
Pharmaceutical Biotechnology VI semester.pdfPharmaceutical Biotechnology VI semester.pdf
Pharmaceutical Biotechnology VI semester.pdf
 

Lec 12. Multidimensional Arrays / Passing Arrays to Functions

  • 1. Lecture 12Lecture 12 Version 1.0Version 1.0 Multidimensional ArraysMultidimensional Arrays Passing Arrays to FuncionPassing Arrays to Funcion
  • 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. 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. 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. 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. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Two Dimensional ArrayTwo Dimensional Array
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh The OutputThe Output
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh Two Dimensional ArraysTwo Dimensional Arrays
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh The OutputThe Output
  • 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. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh Valid DeclarationValid Declaration
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh Invalid DeclarationInvalid Declaration
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh Three Dimensional ArraysThree Dimensional Arrays
  • 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. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Arrays to FunctionsPassing Arrays to Functions
  • 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh OutputOutput
  • 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Arrays to FunctionsPassing Arrays to Functions
  • 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. 19Rushdi Shams, Dept of CSE, KUET, Bangladesh OutputOutput