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 (20)

Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Array in c++
Array in c++Array in c++
Array in c++
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Java arrays
Java arraysJava arrays
Java arrays
 
Array in c#
Array in c#Array in c#
Array in c#
 
Array
ArrayArray
Array
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Arrays
ArraysArrays
Arrays
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Structure in C
Structure in CStructure in C
Structure in C
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Strings in c
Strings in cStrings in c
Strings in c
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 

Viewers also liked

Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in CSmit Parikh
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional arrayRajendran
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)EngineerBabu
 
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 - JavaTpointJavaTpoint.Com
 

Viewers also liked (9)

Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
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)
 
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
 
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
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 

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

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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