SlideShare a Scribd company logo
Arrays
Declaration & Initialization
For understanding the arrays properly, let us consider
the following program:
main( )
{
int x ;
x = 5 ;
x = 10 ;
cout<< x<<endl ;
}
• There are situations in which we would want to store
more than one value at a time in a single variable.
• For example, suppose we wish to arrange the marks
obtained by 100 students
• In such a case we have two options to store these marks
• Construct 100 variables to store marks obtained by 100
different students, i.e. each variable containing one
student’s marks.
• Construct one variable capable of storing or holding all
the hundred values.
• Obviously, the second alternative is better.
• A simple reason for this is, it would be much easier to
handle one variable than handling 100 different variables
Arrays
• When we want to store more than one value at a time
in a single variable, we require an array
• Array is the collection of similar data types stored in
contiguous memory location
• Each data item of an array is called an element.
• Each element is located in separated memory location.
• Each of elements of an array have different index no.
known as subscript
• Thus, an array can be considered as a subscripted
variable
ADVANTAGE:
• Array variable can store more than one value at a time
where other variable can store one value at a time.
An array of integers
• All elements in the array are of type integer
• The length of the array is 10
• The array is indexed from 0 to 9
3 16 -1 0 8 7 1 55 -3 1
An array of integers
• All elements in the array are of type integer
• The length of the array is 10
• The array is indexed from 0 to 9
• The element at index 0 is 3
3 16 -1 0 8 7 1 55 -3 1
index
0
An array of integers
• All elements in the array are of type integer
• The length of the array is 10
• The array is indexed from 0 to 9
• The element at index 4 is 8
3 16 -1 0 8 7 1 55 -3 1
index
4
An array of integers
• All elements in the array are of type integer
• The length of the array is 10
• The array is indexed from 0 to 9
• The element at index 7 is 55
3 16 -1 0 8 7 1 55 -3 1
index
7
An array of integers
• All elements in the array are of type integer
• The length of the array is 10
• The array is indexed from 0 to 9
• The element at index 9 is 1
3 16 -1 0 8 7 1 55 -3 1
index
9
An array of Floats and Characters
• Array of Floats
• Array of Characters
3.5 1.4 7.8 8.8 9.4 9.9 3.5 6.8 5.0 5.5
W E L L C O M E B K
NOT AN ARRAY
3 1.5 -1 0 6.7 R D 5.5 -3 1
Array Declaration
• The statement int A;
declares a single integer variable named A
Syntax: type arrayName [ arraySize ];
• The statement int A[5];
float B[10];
declares
• Array variable A that can hold 5 integer values
• Array variable B that can hold 10 float values
• The size and type of arrays cannot be changed after its
declaration.
arrayy.ppt
Initializing Array
• Syntax:
type arrayName [ arraySize ]={element1,element2….elementN };
• It's possible to initialize an array during declaration.
int A[5] = {35, 20, 40, 57, 19};
• Another method to initialize array during declaration:
int A[] = {35, 20, 40, 57, 19};
OR
A[0]= 35 ;
A[1]= 20 ;
A[2]= 40 ;
A[3]= 57 ;
A[4]= 19 ;
arrayy.ppt
C++ program
• # include<iostream.h>
• #include<conio.h>
• main()
• {
• int x[5] , i;
• cout<<“Enter values into array”<<endl;
• for(i=0;i<5l;i++)
{
• cin>>x[i];
}
• cout<<“The values you entered into array are ”<<endl;
for(i=0;i<5l;i++)
• {
• cout<<x[i]<<endl;
• }
• }
TWO – DIMENTIONAL ARRAY:
If you want to store data into table or matrix form at that time you
can use the two dimensional array.
Declaration of two dimentional array:
Syntax : data_type array-name[dim1][dim2];
Where dim1 indicates total rows and dim2 indicates total
columns.
Ex: ITEM 1 ITEM2ITEM 3
SALES MAN 1 310 275 365
SALES MAN 2 210 190 325
SALES MAN 3 405 235 240
SALES MAN 4 260 300 380
arrayy.ppt
Initializing two dimentional array:
Ex: int table[2][3] = {0,0,0,1,1,1};
int table[2][3] = {
{0,0,0},
{1,1,1}
} ;
Initializing two dimentional array:
When the array is completely initialized with all values,
we need not specify the size of the first dimension. That
is, the statement is permitted.
int table[][3] = {
{0,0,0} ,
{1,1,1)
};
C++ program
• # include<iostream.h>
• #include<conio.h>
• main()
• {
• int x[2][3] , i,j;
• cout<<“Enter values into array”<<endl;
• for(i=0;i<2l;i++)
• {
• for(j=0;j<3;j++)
{
• cin>>x[i][j];
}
}
• cout<<“The values you entered into array are ”<<endl;
• for(i=0;i<2l;i++)
• {
• for(j=0;j<3;j++)
{
• cout<<x[i][j];
}
}
}

More Related Content

Similar to arrayy.ppt (20)

PPTX
Arrays
Abdullahprince787
 
PDF
Week06
hccit
 
PDF
Array-part1
AbishaiAsir
 
PDF
SPL 10 | One Dimensional Array in C
Mohammad Imam Hossain
 
PPTX
Chapter-Five.pptx
berekethailu2
 
PDF
Learn Java Part 8
Gurpreet singh
 
PPTX
Unit 6. Arrays
Ashim Lamichhane
 
PPTX
6 arrays injava
irdginfo
 
PPTX
Array
HarshKumar943076
 
PPTX
Arrays
Neeru Mittal
 
PDF
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
PPT
Arrays
Manthan Dhavne
 
PDF
Arrays in C++
Maliha Mehr
 
PPTX
Programming fundamentals week 12.pptx
dfsdg3
 
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
PPTX
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
PDF
Lecture 6 - Arrays
Syed Afaq Shah MACS CP
 
PPTX
CSE 1102 - Lecture 6 - Arrays in C .pptx
Salim Shadman Ankur
 
PPT
2 arrays
trixiacruz
 
PPTX
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
teddiyfentaw
 
Week06
hccit
 
Array-part1
AbishaiAsir
 
SPL 10 | One Dimensional Array in C
Mohammad Imam Hossain
 
Chapter-Five.pptx
berekethailu2
 
Learn Java Part 8
Gurpreet singh
 
Unit 6. Arrays
Ashim Lamichhane
 
6 arrays injava
irdginfo
 
Arrays
Neeru Mittal
 
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
Arrays in C++
Maliha Mehr
 
Programming fundamentals week 12.pptx
dfsdg3
 
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
Lecture 6 - Arrays
Syed Afaq Shah MACS CP
 
CSE 1102 - Lecture 6 - Arrays in C .pptx
Salim Shadman Ankur
 
2 arrays
trixiacruz
 
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
teddiyfentaw
 

Recently uploaded (20)

DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPTX
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
PPTX
internet básico presentacion es una red global
70965857
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PDF
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPT
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
internet básico presentacion es una red global
70965857
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Orchestrating things in Angular application
Peter Abraham
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
Ad

arrayy.ppt

  • 2. For understanding the arrays properly, let us consider the following program: main( ) { int x ; x = 5 ; x = 10 ; cout<< x<<endl ; }
  • 3. • There are situations in which we would want to store more than one value at a time in a single variable. • For example, suppose we wish to arrange the marks obtained by 100 students • In such a case we have two options to store these marks
  • 4. • Construct 100 variables to store marks obtained by 100 different students, i.e. each variable containing one student’s marks. • Construct one variable capable of storing or holding all the hundred values.
  • 5. • Obviously, the second alternative is better. • A simple reason for this is, it would be much easier to handle one variable than handling 100 different variables
  • 6. Arrays • When we want to store more than one value at a time in a single variable, we require an array • Array is the collection of similar data types stored in contiguous memory location • Each data item of an array is called an element. • Each element is located in separated memory location.
  • 7. • Each of elements of an array have different index no. known as subscript • Thus, an array can be considered as a subscripted variable ADVANTAGE: • Array variable can store more than one value at a time where other variable can store one value at a time.
  • 8. An array of integers • All elements in the array are of type integer • The length of the array is 10 • The array is indexed from 0 to 9 3 16 -1 0 8 7 1 55 -3 1
  • 9. An array of integers • All elements in the array are of type integer • The length of the array is 10 • The array is indexed from 0 to 9 • The element at index 0 is 3 3 16 -1 0 8 7 1 55 -3 1 index 0
  • 10. An array of integers • All elements in the array are of type integer • The length of the array is 10 • The array is indexed from 0 to 9 • The element at index 4 is 8 3 16 -1 0 8 7 1 55 -3 1 index 4
  • 11. An array of integers • All elements in the array are of type integer • The length of the array is 10 • The array is indexed from 0 to 9 • The element at index 7 is 55 3 16 -1 0 8 7 1 55 -3 1 index 7
  • 12. An array of integers • All elements in the array are of type integer • The length of the array is 10 • The array is indexed from 0 to 9 • The element at index 9 is 1 3 16 -1 0 8 7 1 55 -3 1 index 9
  • 13. An array of Floats and Characters • Array of Floats • Array of Characters 3.5 1.4 7.8 8.8 9.4 9.9 3.5 6.8 5.0 5.5 W E L L C O M E B K
  • 14. NOT AN ARRAY 3 1.5 -1 0 6.7 R D 5.5 -3 1
  • 15. Array Declaration • The statement int A; declares a single integer variable named A Syntax: type arrayName [ arraySize ]; • The statement int A[5]; float B[10]; declares • Array variable A that can hold 5 integer values • Array variable B that can hold 10 float values • The size and type of arrays cannot be changed after its declaration.
  • 17. Initializing Array • Syntax: type arrayName [ arraySize ]={element1,element2….elementN }; • It's possible to initialize an array during declaration. int A[5] = {35, 20, 40, 57, 19}; • Another method to initialize array during declaration: int A[] = {35, 20, 40, 57, 19}; OR A[0]= 35 ; A[1]= 20 ; A[2]= 40 ; A[3]= 57 ; A[4]= 19 ;
  • 19. C++ program • # include<iostream.h> • #include<conio.h> • main() • { • int x[5] , i; • cout<<“Enter values into array”<<endl; • for(i=0;i<5l;i++) { • cin>>x[i]; } • cout<<“The values you entered into array are ”<<endl; for(i=0;i<5l;i++) • { • cout<<x[i]<<endl; • } • }
  • 20. TWO – DIMENTIONAL ARRAY: If you want to store data into table or matrix form at that time you can use the two dimensional array. Declaration of two dimentional array: Syntax : data_type array-name[dim1][dim2]; Where dim1 indicates total rows and dim2 indicates total columns. Ex: ITEM 1 ITEM2ITEM 3 SALES MAN 1 310 275 365 SALES MAN 2 210 190 325 SALES MAN 3 405 235 240 SALES MAN 4 260 300 380
  • 22. Initializing two dimentional array: Ex: int table[2][3] = {0,0,0,1,1,1}; int table[2][3] = { {0,0,0}, {1,1,1} } ;
  • 23. Initializing two dimentional array: When the array is completely initialized with all values, we need not specify the size of the first dimension. That is, the statement is permitted. int table[][3] = { {0,0,0} , {1,1,1) };
  • 24. C++ program • # include<iostream.h> • #include<conio.h> • main() • { • int x[2][3] , i,j; • cout<<“Enter values into array”<<endl; • for(i=0;i<2l;i++) • { • for(j=0;j<3;j++) { • cin>>x[i][j]; } }
  • 25. • cout<<“The values you entered into array are ”<<endl; • for(i=0;i<2l;i++) • { • for(j=0;j<3;j++) { • cout<<x[i][j]; } } }