SlideShare a Scribd company logo
ARRAYS IN C ++
ARRAYS:
-An array is defined as the collection of similar type of data items stored at
contiguous memory locations.
- Arrays are the derived data type in C++ programming language which can
store the primitive type of data such as int, char, double, float, etc.
-It also has the capability to store the collection of derived data types, such
as pointers, structure, etc.
-The array is the simplest data structure where each data element can be
randomly accessed by using its index number.
ARRAYSCPP.pptx
ONE DIMENSIONALARRAY:
SYNTAX:
Data_Type array_name[array_size];
ARRAYSCPP.pptx
EXAMPLE
int marks[9]={40,55,63,17,22,68,89,97,89};
MEMORY SIZE OF ARRAY=TOTAL NO
OF ELEMENTS IN ARRAY*DATATYPE
SIZE
// Array declaration by specifying size
int arr1[10];
// declare an array of user specified size
int n = 10;
int arr2[n];
// Array declaration by initializing elements
int arr[] = { 10, 20, 30, 40};
// Array declaration by specifying size and initializing elements
int arr[6] = { 10, 20, 30, 40 };
int marks[5];//declaration of array
INITIALIZATION OF ARRAY
FIRST METHOD:
marks[0]=80;
marks[1]=60;
marks[2]=70;
marks[3]=85;
marks[4]=75;
SECOND METHOD:
for(i=0;i<5;i++)
{
cin>>marks[i];
}
EXAMPLE OF 1 D ARRAY
int main()
{
int values[5];
// taking input and storing it in an array
for(int i = 0; i < 5; ++i)
{
cin>>values[i];
}
// printing elements of an array
for(int i = 0; i < 5; ++i)
{
cout<<values[i];
}
}
MULTI DIMENSIONALARRAYS
• Arrays of arrays.(ie) an array containing one or more arrays.
SYNTAX:
Data_Type array_name[1st dimension][2nd dimension][]..[Nth
dimension] ;
TWO DIMENSIONAL ARRAYS:
Data_Type array_name [][];
int a[n][n];
TWO DIMENSIONAL ARRAY
int x[3][3];
Initializing Two – Dimensional Arrays:
First Method:
int x[3][4] = {0, 1 ,2 ,3 ,4 , 5 , 6 , 7 , 8 , 9 , 10 , 11}
Second Method:
int x[3][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11}};
Third Method:
int x[3][4];
for(int i = 0; i < 3; i++){
for(int j = 0; j < 4; j++){
cin>>x[i][j];
}
}
EXAMPLE OF 2D ARRAY
int main()
{
int disp[2][3];
int i, j;
for(i=0; i<2; i++) {
for(j=0;j<3;j++) {
cout<<"Enter values for array”;
cin>>disp[i][j];
}}
cout<<"Two Dimensional array elements:n";
for(i=0; i<2; i++) {
for(j=0;j<3;j++) {
cout<< disp[i][j];
}
}
}
3D Arrays
Example:
int arr[3][3][3];
3 tables each with 3 rows and 3 columns
JAGGED ARRAYS
- Ragged arrays
- Array of arrays such that member arrays can be of different sizes.
- 2-D arrays with variable number of columns in each row.
int s[4][];
s[0]={1};
s[1]={2,3};
s[2]={4,5,6};
s[3]={7,8,9,10};
arr[][] = { {0, 1, 2},
{6, 4},
{1, 7, 6, 8, 9},
{5} };

More Related Content

PPTX
PPTX
Arrays in c
PDF
array-191103180006.pdf
PPTX
Array Introduction One-dimensional array Multidimensional array
PPTX
Arrays.pptx
PPTX
Arrays_in_c++.pptx
PPTX
BHARGAVIARRAY.PPT.pptx
PDF
Arrays and library functions
Arrays in c
array-191103180006.pdf
Array Introduction One-dimensional array Multidimensional array
Arrays.pptx
Arrays_in_c++.pptx
BHARGAVIARRAY.PPT.pptx
Arrays and library functions

Similar to ARRAYSCPP.pptx (20)

DOCX
PPT
PPTX
array.pptx ppt ggsipu bpit delhi rohini.
PDF
Array Data Structure for programing language
PPT
Multi dimensional arrays
PPTX
Arrays in C language
PPTX
C++ lecture 04
PPTX
PPT
strings.ppt
PPT
7.basic array
PPT
Structured Data Type Arrays
PPTX
arrays in c# including Classes handling arrays
PDF
ARRAYS
PPTX
arrays.pptx
PPT
SP-First-Lecture.ppt
PDF
Arrays-Computer programming
PDF
Class notes(week 4) on arrays and strings
PPTX
Data structure array
PPTX
Arrays-from-Basics-to-Advanced final.pptx
array.pptx ppt ggsipu bpit delhi rohini.
Array Data Structure for programing language
Multi dimensional arrays
Arrays in C language
C++ lecture 04
strings.ppt
7.basic array
Structured Data Type Arrays
arrays in c# including Classes handling arrays
ARRAYS
arrays.pptx
SP-First-Lecture.ppt
Arrays-Computer programming
Class notes(week 4) on arrays and strings
Data structure array
Arrays-from-Basics-to-Advanced final.pptx

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Empowerment Technology for Senior High School Guide
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
1_English_Language_Set_2.pdf probationary
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Computing-Curriculum for Schools in Ghana
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Complications of Minimal Access Surgery at WLH
Cell Types and Its function , kingdom of life
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Empowerment Technology for Senior High School Guide
Weekly quiz Compilation Jan -July 25.pdf
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Indian roads congress 037 - 2012 Flexible pavement
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Final Presentation General Medicine 03-08-2024.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
1_English_Language_Set_2.pdf probationary
History, Philosophy and sociology of education (1).pptx
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Paper A Mock Exam 9_ Attempt review.pdf.
Computing-Curriculum for Schools in Ghana
A systematic review of self-coping strategies used by university students to ...
What if we spent less time fighting change, and more time building what’s rig...
Complications of Minimal Access Surgery at WLH

ARRAYSCPP.pptx

  • 2. ARRAYS: -An array is defined as the collection of similar type of data items stored at contiguous memory locations. - Arrays are the derived data type in C++ programming language which can store the primitive type of data such as int, char, double, float, etc. -It also has the capability to store the collection of derived data types, such as pointers, structure, etc. -The array is the simplest data structure where each data element can be randomly accessed by using its index number.
  • 7. MEMORY SIZE OF ARRAY=TOTAL NO OF ELEMENTS IN ARRAY*DATATYPE SIZE
  • 8. // Array declaration by specifying size int arr1[10]; // declare an array of user specified size int n = 10; int arr2[n]; // Array declaration by initializing elements int arr[] = { 10, 20, 30, 40}; // Array declaration by specifying size and initializing elements int arr[6] = { 10, 20, 30, 40 };
  • 9. int marks[5];//declaration of array INITIALIZATION OF ARRAY FIRST METHOD: marks[0]=80; marks[1]=60; marks[2]=70; marks[3]=85; marks[4]=75; SECOND METHOD: for(i=0;i<5;i++) { cin>>marks[i]; }
  • 10. EXAMPLE OF 1 D ARRAY int main() { int values[5]; // taking input and storing it in an array for(int i = 0; i < 5; ++i) { cin>>values[i]; } // printing elements of an array for(int i = 0; i < 5; ++i) { cout<<values[i]; } }
  • 11. MULTI DIMENSIONALARRAYS • Arrays of arrays.(ie) an array containing one or more arrays. SYNTAX: Data_Type array_name[1st dimension][2nd dimension][]..[Nth dimension] ;
  • 12. TWO DIMENSIONAL ARRAYS: Data_Type array_name [][]; int a[n][n];
  • 14. Initializing Two – Dimensional Arrays: First Method: int x[3][4] = {0, 1 ,2 ,3 ,4 , 5 , 6 , 7 , 8 , 9 , 10 , 11} Second Method: int x[3][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11}}; Third Method: int x[3][4]; for(int i = 0; i < 3; i++){ for(int j = 0; j < 4; j++){ cin>>x[i][j]; } }
  • 15. EXAMPLE OF 2D ARRAY int main() { int disp[2][3]; int i, j; for(i=0; i<2; i++) { for(j=0;j<3;j++) { cout<<"Enter values for array”; cin>>disp[i][j]; }} cout<<"Two Dimensional array elements:n"; for(i=0; i<2; i++) { for(j=0;j<3;j++) { cout<< disp[i][j]; } } }
  • 16. 3D Arrays Example: int arr[3][3][3]; 3 tables each with 3 rows and 3 columns
  • 17. JAGGED ARRAYS - Ragged arrays - Array of arrays such that member arrays can be of different sizes. - 2-D arrays with variable number of columns in each row. int s[4][]; s[0]={1}; s[1]={2,3}; s[2]={4,5,6}; s[3]={7,8,9,10};
  • 18. arr[][] = { {0, 1, 2}, {6, 4}, {1, 7, 6, 8, 9}, {5} };