lecture-8
lecture-8
• A problem to input 1000 integers values and print them in reverse order
Arrays Fundamentals
• A problem to input 1000 integers values and print them in reverse order
Arrays Fundamentals
• A problem to input 1000 integers values and print them in reverse order
Like printing arrays, there is no single statement in the language that says "copy an entire
array into another array". The array elements must be copied individually.
Arrays Fundamentals
1: #include <iostream>
2:
3: int main()
4: {
5: short age;
6: age=23;
7: std::cout << age << std::endl;
8: return 0;
9: }
1: #include <iostream>
2:
3: int main()
4: {
5: short age[4];
6: age[0]=23;
7: age[1]=34;
8: age[2]=65;
9: age[3]=74;
10: return 0;
11: }
Printing Array Elements
Index 13
• Initializing arrays in Declarations;
int
age[5]={23,10,16,34,30};
int age[ ]={23,10,16,34,30};
Aggregate Operations
• Aggregate Array Operations
int x [20];
int y [20];
X=y; // not valid
X == y; // not valid
cout <<x; // not valid
x=x *y; // not valid
return x; // not valid
Dosomething(x); // valid
Two-Dimensional Arrays
• Used to represent items in a table
Tow-dimensional
with rows and columns, provided
array: A collection of
each item in the table is of the
components, all of the
same data type.
same type, structured in
two dimensions. Each
[0] [1] [2] row 0, column 2
component is accessed
[0] by a pair of indexes that
represent the
[1] component’s position in
each dimension.
[2]
Two Dim-Arrays
• Float alpha [NUM_ROWS][NUM_COLS];
• Alpha[0][5]=30.5;
• Syntax
ArrayName [indexExpression][indexExpression]
total=total + arr[1][col]; …