SlideShare une entreprise Scribd logo
1  sur  15
A Presentation on
Array
Introduction:
Array is a data structure consisting of a
collection of elements of related data types.
Defined in same manner as ordinary variable
expect size specification.
Syntax :
data_type array_name[ no. of elements];
Is also known as subscripted value.
No limits on dimension of arrays.
Types of array:
1)One Dimensional Array:
Only one subscript also called one subscript.
1D array variable are declared with data type
followed by variable name and a pair of square
brackets.
Syntax:
data_type array_name[ ];
Array size most be integer constant greater than
zero with valid data type.
Initialization of 1D array:
Should be initialized as other variable .
Examples:
int array [6]={1,3,5,7,9,8};
int array [5]={3,5};
int array [ ]={2,4,6,7};
Note: We can’t initialized an array using a variable
For example:
int x=5;
int array [x];
Above example is illegal.
2) Two dimensional array:
Simplest form of multi dimensional array .
Requires two pair of square brackets.
Syntax:
To declare 2D array of size x , y.
data_type array_name[x][y];
First bracket is know as number of rows and
second numbers of columns.
Initialization of 2D array:
2D array is initialized by specifying bracket value
of each value .
Following is an array with 3 rows and 4 columns:
int a[3][4]={ {0,1,2,3},
{4,5,6,7},
{8,9,4,7} };
Also equivalent to
int a[3][4]={0,1,2,3,4,5,6,7,8,9,4,7};
3) Multi-dimentional array:
Has more than one subscript.
General form of multidimensional array:
data_type array_name [size 1][size 2]…[size n];
For example:
int array [2][3][2]={ { {2,4},
{3,5},
{5,7}
},
{ {3,5},
{7,8},
{1,2}
} };
Accessing 2-D array elements:
An element in 2-D array is accessed by using subscripts, i.e. rows
and column index of the array.
For example:
Arrays as argument to function:
To pass 1D array as argument to function, we should declared
function formal parameter in three ways.
Way-1:
Formal parameter as pointer
void function (int *aru)
{…}
Way-2:
Formal parameter as sized array
void function(int aru[10])
{…}
Way-3:
Formal parameter as unsized array
void function(int aru [ ])
{…}
Example:
Sample program using 2-D array:
Array application :
Array is used for maintaining multiple variable
names using single name.
Array can be used for sorting element using
different sorting techniques.
Array can perform matrix operation.
Array can be used in recursive function:
-When the function calls another function
or the same function, the current values
can be stored in array and can be
retrieved back.
Limitation of array:
1.Array is static data structure.
2.Can hold data only belonging to same data type
3.Deletion is not easy because the element are
stored in contiguous memory location.
4.Bound checking :
process of checking limit of array.
5.Shortage of memory may occur if we don’t know
required memory in advanced.
6.Wastage of memory may occur if array of large
size is defined and less element is processed.
Points to remember:
An array is similar to an ordinary variable except it
can stored multiple element of same type.
And it is also know as subscripted variable.
Elements of an array are accessed by specifying the
index of desired element within square brackets .
Array subscripts must be a integer type.(int, long
int, char ,etc.)
However, big an array it elements are always stored
in contiguous memory location
Array indices starts at zero and goes to one less
than the size of array.
ANY QUESTIONS???

Contenu connexe

Tendances (20)

arrays in c
arrays in carrays in c
arrays in c
 
Array in c++
Array in c++Array in c++
Array in c++
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Array ppt
Array pptArray ppt
Array ppt
 
Array in c
Array in cArray in c
Array in c
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Array in C
Array in CArray in C
Array in C
 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisation
 
Array operations
Array operationsArray operations
Array operations
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Array
ArrayArray
Array
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Arrays
ArraysArrays
Arrays
 
2D Array
2D Array 2D Array
2D Array
 

En vedette

Solución del modelo de examen
Solución del modelo de examenSolución del modelo de examen
Solución del modelo de examenRosa Contramaestre
 
Deep Dive Training Energy Efficiency in Industrial Processes
Deep Dive TrainingEnergy Efficiency in Industrial ProcessesDeep Dive TrainingEnergy Efficiency in Industrial Processes
Deep Dive Training Energy Efficiency in Industrial ProcessesChristoph Emde
 
González valentín catàleg_competic2
González valentín catàleg_competic2González valentín catàleg_competic2
González valentín catàleg_competic2antonigau
 
Buyer'sGuideIssuu
Buyer'sGuideIssuuBuyer'sGuideIssuu
Buyer'sGuideIssuuSusan Horak
 
Mobile Banking Student Presentation
Mobile Banking Student PresentationMobile Banking Student Presentation
Mobile Banking Student PresentationRalf Waubke
 
White Paper Organizational Design
White Paper Organizational DesignWhite Paper Organizational Design
White Paper Organizational DesignPablo Borrero
 
CV-Jacqui Armitage - May 2016
CV-Jacqui Armitage - May 2016CV-Jacqui Armitage - May 2016
CV-Jacqui Armitage - May 2016Jacqui Armitage
 
12 najpiękniejszych planerów wg Przedsiebiorcza.com
12 najpiękniejszych planerów wg Przedsiebiorcza.com12 najpiękniejszych planerów wg Przedsiebiorcza.com
12 najpiękniejszych planerów wg Przedsiebiorcza.comJoanna Długa
 
Statistical Analysis of Interrelationship between Money Supply Exchange Rates...
Statistical Analysis of Interrelationship between Money Supply Exchange Rates...Statistical Analysis of Interrelationship between Money Supply Exchange Rates...
Statistical Analysis of Interrelationship between Money Supply Exchange Rates...Atif Ahmed
 
WindEnergyFinal-2-2
WindEnergyFinal-2-2WindEnergyFinal-2-2
WindEnergyFinal-2-2Danny Farr
 
Desenvolvendo aplicações Cross-Platform com Xamarin
Desenvolvendo aplicações Cross-Platform com XamarinDesenvolvendo aplicações Cross-Platform com Xamarin
Desenvolvendo aplicações Cross-Platform com XamarinJúnior Porfirio
 
Financial Sector Performance and Conceptual Framework
Financial Sector Performance and Conceptual FrameworkFinancial Sector Performance and Conceptual Framework
Financial Sector Performance and Conceptual FrameworkAtif Ahmed
 

En vedette (20)

Doctrina
DoctrinaDoctrina
Doctrina
 
Solución del modelo de examen
Solución del modelo de examenSolución del modelo de examen
Solución del modelo de examen
 
Praktek
PraktekPraktek
Praktek
 
Deep Dive Training Energy Efficiency in Industrial Processes
Deep Dive TrainingEnergy Efficiency in Industrial ProcessesDeep Dive TrainingEnergy Efficiency in Industrial Processes
Deep Dive Training Energy Efficiency in Industrial Processes
 
González valentín catàleg_competic2
González valentín catàleg_competic2González valentín catàleg_competic2
González valentín catàleg_competic2
 
Buyer'sGuideIssuu
Buyer'sGuideIssuuBuyer'sGuideIssuu
Buyer'sGuideIssuu
 
Mobile Banking Student Presentation
Mobile Banking Student PresentationMobile Banking Student Presentation
Mobile Banking Student Presentation
 
White Paper Organizational Design
White Paper Organizational DesignWhite Paper Organizational Design
White Paper Organizational Design
 
CV-Jacqui Armitage - May 2016
CV-Jacqui Armitage - May 2016CV-Jacqui Armitage - May 2016
CV-Jacqui Armitage - May 2016
 
12 najpiękniejszych planerów wg Przedsiebiorcza.com
12 najpiękniejszych planerów wg Przedsiebiorcza.com12 najpiękniejszych planerów wg Przedsiebiorcza.com
12 najpiękniejszych planerów wg Przedsiebiorcza.com
 
resume 2015
resume 2015resume 2015
resume 2015
 
Statistical Analysis of Interrelationship between Money Supply Exchange Rates...
Statistical Analysis of Interrelationship between Money Supply Exchange Rates...Statistical Analysis of Interrelationship between Money Supply Exchange Rates...
Statistical Analysis of Interrelationship between Money Supply Exchange Rates...
 
WindEnergyFinal-2-2
WindEnergyFinal-2-2WindEnergyFinal-2-2
WindEnergyFinal-2-2
 
Desenvolvendo aplicações Cross-Platform com Xamarin
Desenvolvendo aplicações Cross-Platform com XamarinDesenvolvendo aplicações Cross-Platform com Xamarin
Desenvolvendo aplicações Cross-Platform com Xamarin
 
Encryption ppt
Encryption pptEncryption ppt
Encryption ppt
 
Internet
InternetInternet
Internet
 
My Invoice Finance
My Invoice FinanceMy Invoice Finance
My Invoice Finance
 
Resume
ResumeResume
Resume
 
Financial Sector Performance and Conceptual Framework
Financial Sector Performance and Conceptual FrameworkFinancial Sector Performance and Conceptual Framework
Financial Sector Performance and Conceptual Framework
 
Phonics
Phonics Phonics
Phonics
 

Similaire à Array

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.pdfKirubelWondwoson1
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loopssangrampatil81
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in Carshpreetkaur07
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdfHEMAHEMS5
 
12000121037.pdf
12000121037.pdf12000121037.pdf
12000121037.pdfAVIWORLD1
 
unit1Intro_final.pptx
unit1Intro_final.pptxunit1Intro_final.pptx
unit1Intro_final.pptxDEEPAK948083
 
Arrays declartion and initialization
Arrays declartion and initializationArrays declartion and initialization
Arrays declartion and initializationsangrampatil81
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersANUSUYA S
 

Similaire à Array (20)

arrays.docx
arrays.docxarrays.docx
arrays.docx
 
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 accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loops
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
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.pptx Arrays.pptx
Arrays.pptx
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Cunit3.pdf
Cunit3.pdfCunit3.pdf
Cunit3.pdf
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
12000121037.pdf
12000121037.pdf12000121037.pdf
12000121037.pdf
 
unit1Intro_final.pptx
unit1Intro_final.pptxunit1Intro_final.pptx
unit1Intro_final.pptx
 
Unit 2
Unit 2Unit 2
Unit 2
 
Arrays declartion and initialization
Arrays declartion and initializationArrays declartion and initialization
Arrays declartion and initialization
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
DEMO.ppt
DEMO.pptDEMO.ppt
DEMO.ppt
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Arrays
ArraysArrays
Arrays
 

Dernier

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Dernier (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Array

  • 2. Introduction: Array is a data structure consisting of a collection of elements of related data types. Defined in same manner as ordinary variable expect size specification. Syntax : data_type array_name[ no. of elements]; Is also known as subscripted value. No limits on dimension of arrays.
  • 3. Types of array: 1)One Dimensional Array: Only one subscript also called one subscript. 1D array variable are declared with data type followed by variable name and a pair of square brackets. Syntax: data_type array_name[ ]; Array size most be integer constant greater than zero with valid data type.
  • 4. Initialization of 1D array: Should be initialized as other variable . Examples: int array [6]={1,3,5,7,9,8}; int array [5]={3,5}; int array [ ]={2,4,6,7}; Note: We can’t initialized an array using a variable For example: int x=5; int array [x]; Above example is illegal.
  • 5. 2) Two dimensional array: Simplest form of multi dimensional array . Requires two pair of square brackets. Syntax: To declare 2D array of size x , y. data_type array_name[x][y]; First bracket is know as number of rows and second numbers of columns.
  • 6. Initialization of 2D array: 2D array is initialized by specifying bracket value of each value . Following is an array with 3 rows and 4 columns: int a[3][4]={ {0,1,2,3}, {4,5,6,7}, {8,9,4,7} }; Also equivalent to int a[3][4]={0,1,2,3,4,5,6,7,8,9,4,7};
  • 7. 3) Multi-dimentional array: Has more than one subscript. General form of multidimensional array: data_type array_name [size 1][size 2]…[size n]; For example: int array [2][3][2]={ { {2,4}, {3,5}, {5,7} }, { {3,5}, {7,8}, {1,2} } };
  • 8. Accessing 2-D array elements: An element in 2-D array is accessed by using subscripts, i.e. rows and column index of the array. For example:
  • 9. Arrays as argument to function: To pass 1D array as argument to function, we should declared function formal parameter in three ways. Way-1: Formal parameter as pointer void function (int *aru) {…} Way-2: Formal parameter as sized array void function(int aru[10]) {…} Way-3: Formal parameter as unsized array void function(int aru [ ]) {…}
  • 11. Sample program using 2-D array:
  • 12. Array application : Array is used for maintaining multiple variable names using single name. Array can be used for sorting element using different sorting techniques. Array can perform matrix operation. Array can be used in recursive function: -When the function calls another function or the same function, the current values can be stored in array and can be retrieved back.
  • 13. Limitation of array: 1.Array is static data structure. 2.Can hold data only belonging to same data type 3.Deletion is not easy because the element are stored in contiguous memory location. 4.Bound checking : process of checking limit of array. 5.Shortage of memory may occur if we don’t know required memory in advanced. 6.Wastage of memory may occur if array of large size is defined and less element is processed.
  • 14. Points to remember: An array is similar to an ordinary variable except it can stored multiple element of same type. And it is also know as subscripted variable. Elements of an array are accessed by specifying the index of desired element within square brackets . Array subscripts must be a integer type.(int, long int, char ,etc.) However, big an array it elements are always stored in contiguous memory location Array indices starts at zero and goes to one less than the size of array.