SlideShare a Scribd company logo
1 of 19
Topic:
2D Array
Group Members:
 Ehatsham Riaz
Array:
 Consecutive group of memory locations
― All of which have the same type
Index:
 Position number used to refer to a specific
location/element
 Place in square brackets
― Must be positive integer or integer expression
 First element has index zero
Definition:
Two-dimensional Array: a
collection of a fixed number of
components arranged in two
dimensions
All components are of the same type
Syntax:
 The syntax for declaring a two-dimensional array
is:
DataType ArrayName[rowsize][colsize];
where rowsize and colsize are expressions yielding
positive integer values
Example: int data[3][4];
― Data is a TWO Dimensional array of size 3*4
elements
 The two expressions rowsize and colsize specify
the number of rows and the number of columns,
respectively, in the array
 Two-dimensional arrays are sometimes called
matrices or tables
 Multiple arrays of the same type can be declared
in a single declaration
―Use a comma-separated list of names and
sizes
int sales[10][5];
Each array Element is identified by its Row and
column position
Accessing Array Components
 The syntax to access a component of a two-
dimensional array is:
arrayName[indexexp1][indexexp2]
where indexexp1 and indexexp2 are expressions
yielding nonnegative integer values
 indexexp1 specifies the row position and
indexexp2 specifies the column position
inStock[1][3]=15;
Processing Two-Dimensional
Arrays:
 A two-dimensional array can be processed
in three different ways:
1. Process the entire array
2. Process a particular row of the array, called
row processing
3. Process a particular column of the array,
called column processing
 Each row and each column of a two-dimensional
array is a one-dimensional array
 When processing a particular row or column of a
two-dimensional array
― we use algorithms similar to processing one-
dimensional arrays
Example:
Initialisation of 2D Array
#include <iostream>
int main()
{
int _2DArray[5][6] = { { 1, 2, 3, 4, 5, 6},
{ 7, 8, 9, 0, 1, 2},
{ 3, 4, 5} };
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 6; j++)
{
cout << _2DArray [i][j];
}
cout << endl;
}
cout << endl;
return 0;
}
Output:
1 2 3 4 5 6
7 8 9 0 1 2
3 4 5 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Example
Write a function in c++ which accepts a 2D array of integers
and its size as arguments and displays the elements of middle
row and the elements of middle column.
const int S = 5;
void DisplayMidle( int A[S][S], int S)
{ int mid = S/2;
int i;
cout << “ n Middle row”;
for (i=0 ; i<S; i++)
cout << A[ mid ][ i ]<< “ “;
cout<< “ n Middle Column ”;
for (i = 0; i<S; i++)
cout<<A[i][ mid ]<< “ “
cout << endl;
}
Thank You 

More Related Content

What's hot

Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional arrayRajendran
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Presentation on array
Presentation on array Presentation on array
Presentation on array topu93
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2Rajendran
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structureVardhil Patel
 

What's hot (20)

Array ppt
Array pptArray ppt
Array ppt
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Hashing
HashingHashing
Hashing
 
Array data structure
Array data structureArray data structure
Array data structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Array in c++
Array in c++Array in c++
Array in c++
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Sorting
SortingSorting
Sorting
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
List in Python
List in PythonList in Python
List in Python
 
Stacks
StacksStacks
Stacks
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 

Viewers also liked

Viewers also liked (9)

2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
array
array array
array
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Array in C
Array in CArray in C
Array in C
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar to 2D Array (20)

array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Chapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdfChapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdf
 
Arrays
ArraysArrays
Arrays
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
Arrays
ArraysArrays
Arrays
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Arrays
ArraysArrays
Arrays
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Lecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdfLecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdf
 
Ch08
Ch08Ch08
Ch08
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 

More from Ehatsham Riaz

whats is Grammar and TYPES OF GRAMMAR
whats is Grammar and TYPES OF GRAMMARwhats is Grammar and TYPES OF GRAMMAR
whats is Grammar and TYPES OF GRAMMAREhatsham Riaz
 
Stress management and stress handling hand out
Stress management and stress handling hand outStress management and stress handling hand out
Stress management and stress handling hand outEhatsham Riaz
 
STRESS MANAGEMENT And STRESS HANDLING
STRESS MANAGEMENT And STRESS HANDLINGSTRESS MANAGEMENT And STRESS HANDLING
STRESS MANAGEMENT And STRESS HANDLINGEhatsham Riaz
 
Mealy and moore machine
Mealy and moore machineMealy and moore machine
Mealy and moore machineEhatsham Riaz
 
Muhammad Raza Saeed Tech-Entrepreneur
Muhammad Raza Saeed Tech-Entrepreneur Muhammad Raza Saeed Tech-Entrepreneur
Muhammad Raza Saeed Tech-Entrepreneur Ehatsham Riaz
 
Jahan ara - TECH Entrepreneure
Jahan ara - TECH EntrepreneureJahan ara - TECH Entrepreneure
Jahan ara - TECH EntrepreneureEhatsham Riaz
 

More from Ehatsham Riaz (10)

whats is Grammar and TYPES OF GRAMMAR
whats is Grammar and TYPES OF GRAMMARwhats is Grammar and TYPES OF GRAMMAR
whats is Grammar and TYPES OF GRAMMAR
 
Stress management and stress handling hand out
Stress management and stress handling hand outStress management and stress handling hand out
Stress management and stress handling hand out
 
STRESS MANAGEMENT And STRESS HANDLING
STRESS MANAGEMENT And STRESS HANDLINGSTRESS MANAGEMENT And STRESS HANDLING
STRESS MANAGEMENT And STRESS HANDLING
 
Mealy and moore machine
Mealy and moore machineMealy and moore machine
Mealy and moore machine
 
Roza suom
Roza suomRoza suom
Roza suom
 
suffixation
suffixation suffixation
suffixation
 
English report
English reportEnglish report
English report
 
Muhammad Raza Saeed Tech-Entrepreneur
Muhammad Raza Saeed Tech-Entrepreneur Muhammad Raza Saeed Tech-Entrepreneur
Muhammad Raza Saeed Tech-Entrepreneur
 
Jahan ara - TECH Entrepreneure
Jahan ara - TECH EntrepreneureJahan ara - TECH Entrepreneure
Jahan ara - TECH Entrepreneure
 
History Of Calculas
History Of CalculasHistory Of Calculas
History Of Calculas
 

Recently uploaded

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Recently uploaded (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

2D Array

  • 2. Array:  Consecutive group of memory locations ― All of which have the same type Index:  Position number used to refer to a specific location/element  Place in square brackets ― Must be positive integer or integer expression  First element has index zero
  • 3. Definition: Two-dimensional Array: a collection of a fixed number of components arranged in two dimensions All components are of the same type
  • 4. Syntax:  The syntax for declaring a two-dimensional array is: DataType ArrayName[rowsize][colsize]; where rowsize and colsize are expressions yielding positive integer values Example: int data[3][4]; ― Data is a TWO Dimensional array of size 3*4 elements
  • 5.  The two expressions rowsize and colsize specify the number of rows and the number of columns, respectively, in the array  Two-dimensional arrays are sometimes called matrices or tables  Multiple arrays of the same type can be declared in a single declaration ―Use a comma-separated list of names and sizes
  • 7. Each array Element is identified by its Row and column position
  • 8. Accessing Array Components  The syntax to access a component of a two- dimensional array is: arrayName[indexexp1][indexexp2] where indexexp1 and indexexp2 are expressions yielding nonnegative integer values  indexexp1 specifies the row position and indexexp2 specifies the column position
  • 10. Processing Two-Dimensional Arrays:  A two-dimensional array can be processed in three different ways: 1. Process the entire array 2. Process a particular row of the array, called row processing 3. Process a particular column of the array, called column processing
  • 11.  Each row and each column of a two-dimensional array is a one-dimensional array  When processing a particular row or column of a two-dimensional array ― we use algorithms similar to processing one- dimensional arrays
  • 13.
  • 14.
  • 15.
  • 16. Initialisation of 2D Array #include <iostream> int main() { int _2DArray[5][6] = { { 1, 2, 3, 4, 5, 6}, { 7, 8, 9, 0, 1, 2}, { 3, 4, 5} }; for (int i = 0; i < 5; i++) { for (int j = 0; j < 6; j++) { cout << _2DArray [i][j]; } cout << endl; } cout << endl; return 0; }
  • 17. Output: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 18. Example Write a function in c++ which accepts a 2D array of integers and its size as arguments and displays the elements of middle row and the elements of middle column. const int S = 5; void DisplayMidle( int A[S][S], int S) { int mid = S/2; int i; cout << “ n Middle row”; for (i=0 ; i<S; i++) cout << A[ mid ][ i ]<< “ “; cout<< “ n Middle Column ”; for (i = 0; i<S; i++) cout<<A[i][ mid ]<< “ “ cout << endl; }

Editor's Notes

  1. Memory slotsss ban jate han