6. • It is derived data type.
• The nature of array is static (fix).
• Array is a collection of similar or
homogeneous data type.
• Array is also known subscript variable
or index variable.
7. • The lower bond of an array is zero 0.
• The upper bond of an array is n-1.
for ex.-int a[9] is an array that stores 9 integers
• Array index start with zero(0).
• Array end with n-1.
0 1 2 3 4 5 6 7 8
100 102 104 106 108 110 112 114 116
index
elements
Memory address
9. NEED FOR AN ARRAY
• To store large number of variables of same type under a
single variable.
• E.g.
To store Marks of 50 students.
Record of sales of 100 salesman.
12. A list of items can be given one variable name using
only one subscript and such a variable is called a one-
dimensional Array.
•Syntax
data_type ArrayName[size];
data_type : is a valid data type like int, float,char
Arrayname : is a valid identifier
size : maximum number of elements that can
be stored in array
13. 1. Declaration of on Array
To declare an array to syntax is-
Data_ type variablename [size];
o The type of data which you
want to store like – int , float
, char.
o Means the name
of an Array.
o The number of Array
type variable.
Ex.- int a [3];
• Type of array variable is “integer”.
• Its variable name is a.
• 3 is the size of the array.
14. 2. Initialization
• An elements of an array must be initialized, otherwise they
may contain “garbage” value.
• An array can be initialized at either of the following stages
o At compile time
o At run time
• At the time of declaration and
initialization at the same time.
• For ex.- int a[5]={1,2,3,4,5}
An array can be explicitly in
initialization at run time.
• To initialize multiple array variable for loop is used.
for ex.-
for (i=0;i<5;i++)
{
scanf (“%d”,&a[i]);
}
15. 3.Assessing
• To print the element of an array is known as
assessing.
• To assessing the element of an array for loop is
used frequently.
for ex.-
for (i=0; i<5 ;i++)
{
printf (“%d”,a[i]);
} OUTPUT:
0
1
2
3
4
16. Examples:-
1) Enter a one-d array
#include<stdio.h>
int main()
{
int a[10],i;
printf(“enter the array=“);
for(i=0;i<10;i++)
{
scanf(“%d”,&a[i]);
}
printf(“the entered array is=“);
for(i=0;i<10;i++)
{
printf(“%d”,a[i]);
}
return(0);
}
18. • C allows us to define such tables of items by using
two-dimensional arrays.
•The two dimensional array are declared as follows-
type array_name[row_size][column_size];
For ex.- int a [3][2];
Data type
Array name Row=3
Column=2
19. 1. Declaration 2D ARRAY
• To declare an array to syntax is.
• The syntax of 2D array is
datatype arrayname[row] [column];
2.Initializing 2D ARRAY
• Like 1D array ,2D array initialized.
• Tow for loop is used .
ex.-
for (i=0 ;i<3; i++)
{
for (j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
20. 3.Assessing 2D ARRAY
• For loop is used.
Ex.-
for (i=0; i<3; i++)
{
for(j=0; j<3;j++)
{
printf(“t%d”,a[i][j]);
}
print(“n”);
}
• To print the element of an array
is known as assessing.
21. /* addition of two matrix/*
#include<stdio.h>
int main()
{
int i,j;
int a[3][3],b[3][3],c[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix a=”);
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix b=”);
scanf(“%d”,&b[i][j]);
}
24. /*subtraction of two matrix/*
#include<stdio.h>
int main()
{
int i,j;
int a[3][3],b[3][3],c[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix a=”);
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix b=”);
scanf(“%d”,&b[i][j]);
}
27. /*multiplication of two matrix/*
#include<stdio.h>
int main()
{
int i,j,k;
int a[3][3],b[3][3],c[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix a=”);
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix b=”);
scanf(“%d”,&b[i][j]);
}
32. • C allows arrays of three or more dimensions. The exact limit
is determined by the compiler
•Syntax-
Datatype aray_name[s1][s2][s3]………….[Sm];
• For ex-
int MyArray[2][3][4];
33.
34. DIFFERENCE
1D
1. 1D Array contains
single row and
multiple columns.
2. 1D Array is a
simple collection
of elements.
3. Ex:-
2d
1. 2D Array contains
multiple row and
multiple columns.
2. 2D Array is a
collection of 1D
Array .
3. Ex:-
1 2 3 4 1 2 3 4
A 1 2 3
B 4 5 6
C 7 8 9
36. Array Applications
• Array can be used for sorting elements.
• Array can perform matrix operation.
• Array can be used to sum all the
elements.
• Array can be stores elements of same
data type.
37. • Given a list of test scores, determine the maximum
and minimum scores.
• Read in a list of student names and rearrange
them in alphabetical order (sorting).
• Given the height measurements of students in a
class, output the names of those students who are
taller than average.
39. Advantages
It is used to represent multiple data of same type by assigning only
single name.
It can be used to implement other data structures like –
linked lists , stacks ,queue etc….
2D array are used to represent matrices.
40. Disadvantages
We must know array is static structure It means that array is fixed size. The
memory which is allocated to array can not be increased or reduced.
Since array is of fixed size , if we allocate more memory than requirement then the
memory space will be wasted . And if we allocate less memory than requirement
than it will create problem.
The elements of array are stored in consecutive memory location. So insertions
and deletion are very difficult and time consuming.
41. Programming in ANSI
(E balagurusamy)
Thank you Chetan Sir for giving me this topic
I would like to thank my friends who
helped meEkta, Sakina, Kunal