SlideShare a Scribd company logo
ARRAYS IN C
PRESENTED BY:
Narra bhargavi
22AJ1A0562
CSE-A
INTRODUCTION
• We know the fundamental data types, namely
char, int, float, double and it’s variations.
• Although these types are very useful, the
variable of these types can store only one value
at a given time.
• Therefore, these data types can be used only to
handle limited amounts of data.
• In many applications we need handle large
volume of data for processing.
• To process such large amounts of data we need
a powerful data type.
DEFINITION OF ARRAY
• An array is a fixed–size sequenced collection of
elements of same data type
• In simplest form, an array can be used to
represent a list of numbers, a list of names.
• An array is a collection of similar data items,
that are stored under a common name.
• A value in an array is identified by index or
subscript enclosed in square bracket with array
name.
FEATURES OF ARRAYS
• An array is a derived data type. It is used to
represent a collection of elements of the same
data type.
• The elements can be accessed with base
address (index) and the subscript defined for
the position of the element.
• The elements in an array are stored in
contiguous memory location.
• It is easier to refer the array elements by simply
incrementing the value of the subscript.
TYPES OF ARRAYS
1. One dimensional array
2. Two dimensional array
3. Multidimensional array
ONE DIMENSIONAL ARRAY
The collection of data items can be
stored under a variable name using only
one subscript
ARRAY DECLARATION
The general form of array declaration is:
data_type array_variable-name[size];
• Data_type – specifies the type of element that
will be contained in the array , such as int, char
• size –indicates the maximum number of
elements that can be stored inside the array.
EXAMPLE
• For example we want to represent a set of five numbers,
say (10,20,30,40,50) by an array variable number, then we
may declare the variable number as follows
int number[5];
• and the computer reserves five storage locations as shown
below:
Number[0]
Number[1]
Number[2]
Number[3]
Number[4]
ARRAY INTIALIZATION
Syntax:
data_type array_variable-name[SIZE]={LIST OF VALUE}
EXAMPLE :
int number[5]={10,20,30,40,50};
Number[0]
Number[1]
Number[2]
Number[3]
Number[4]
fv
10
20
30
40
50
MORE EXAMPLES FOR ARRAY INITIALIZATION
int counter[ ]= {10,20,30,40,50};
char name[ ]= { ’J’ , ’H’ , ’O’ , ’N’ , ’0” };
alternatively,
char name[ ]= “john”; //array with string
int number[5]={10,20};
number[0]=10,number[1]=20,
number[2]=0,number[3]=0,number[4]=0
•we can also initialize an array with scanf() function.
for example,
int x[5];
printf(“enter the values:”);
scanf(“%d%d%d”,&x[0],&x[1],&x[2]);
EXAMPLE PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],sum=0,i;
printf(“Enter 5 numbers”);
for(i=0;i<5;i++)
{
scanf(“%dn”,&a[i]);
sum=sum+a[i];
}
printf(“the sum of given numbers is : %dn”, sum);
}
TWO DIMENSIONAL ARRAY
SYNTAX:
data_type array_name [row-size][column-size];
INITIAZING TWO DIMENSIONAL ARRAY:
Like one dimensional arrays, two dimensional arrays can be
initialized by their declaration
int table[2][3] = {0,0,0,1,1,1};
will assigns the values as follows,
table[0][1]=0, table[0][1]=0, table[0][2]=0,
table[1][0]=1, table[1][1]=1, table[1][2]=1
the above statement can be written as
int table[2][3]={{0,0,0},{1,1,1}};
also
int table[2][3] = {
{0,0,0},
{1,1,1}
};
Example program
#include <stdio.h>
main()
{
int m, n, i, j, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of matrix ");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrixn");
for ( i = 0 ; i< m ; i++ )
for ( j = 0 ; j < n ; j++ )
scanf("%d", &first[i][j]);
printf("Enter the elements of second matrixn");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
scanf("%d", &second[i][j]);
for ( i= 0 ; i < m ; i++ )
for ( j = 0 ; j< n ; j++ )
sum[i][j] = first[i][j] + second[i][j];
printf("Sum of entered matrices:-n");
for ( i= 0 ; i< m ; i++ )
{
for ( j = 0 ; j < n ; j++ )
printf("%dt", sum[i][j]);
printf("n");
}
return 0;
}
MULTI-DIMENSIONAL ARRAY
C allows arrays of more-dimensions called multi-
dimensional array.
The general form of a multi-dimensional array is:
Type array-name[s1][s2][s3]…..[sn]
Where ‘s’ is the size of the dimension
int survey[3][5][2];
float table[5][4][5][3];

More Related Content

PPTX
Arrays in c
PDF
Array and its types and it's implemented programming Final.pdf
PDF
Arrays-Computer programming
PPTX
Arrays basics
PPTX
Programming in c Arrays
PDF
PDF
Introduction to Arrays in C
Arrays in c
Array and its types and it's implemented programming Final.pdf
Arrays-Computer programming
Arrays basics
Programming in c Arrays
Introduction to Arrays in C

Similar to BHARGAVIARRAY.PPT.pptx (20)

PPTX
C (PPS)Programming for problem solving.pptx
PDF
Array
PPTX
Arrays 1D and 2D , and multi dimensional
PPTX
Basic array in c programming
PPT
Arrays
PPTX
Chapter 13.pptx
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
PPTX
Arrays in c
PPT
Array THE DATA STRUCTURE. ITS THE STRUCT
PPTX
PDF
C Language Lecture 10
PPTX
Arrays & Strings
PPTX
Array ppt you can learn in very few slides.
PPTX
Arrays In C Language
PPTX
Arrays in C language
PPTX
Array 2 hina
PPTX
Array.pptx
PDF
SlideSet_4_Arraysnew.pdf
PPTX
PDF
Array in C.pdf
C (PPS)Programming for problem solving.pptx
Array
Arrays 1D and 2D , and multi dimensional
Basic array in c programming
Arrays
Chapter 13.pptx
Unit4pptx__2024_11_ 11_10_16_09.pptx
Arrays in c
Array THE DATA STRUCTURE. ITS THE STRUCT
C Language Lecture 10
Arrays & Strings
Array ppt you can learn in very few slides.
Arrays In C Language
Arrays in C language
Array 2 hina
Array.pptx
SlideSet_4_Arraysnew.pdf
Array in C.pdf
Ad

Recently uploaded (20)

PPTX
AgentX UiPath Community Webinar series - Delhi
PPTX
anatomy of limbus and anterior chamber .pptx
PPTX
Road Safety tips for School Kids by a k maurya.pptx
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PPT
Chapter 6 Design in software Engineeing.ppt
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Internship_Presentation_Final engineering.pptx
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPT
Drone Technology Electronics components_1
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
AgentX UiPath Community Webinar series - Delhi
anatomy of limbus and anterior chamber .pptx
Road Safety tips for School Kids by a k maurya.pptx
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
Arduino robotics embedded978-1-4302-3184-4.pdf
“Next-Gen AI: Trends Reshaping Our World”
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
Chapter 6 Design in software Engineeing.ppt
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
OOP with Java - Java Introduction (Basics)
Internship_Presentation_Final engineering.pptx
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Drone Technology Electronics components_1
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
bas. eng. economics group 4 presentation 1.pptx
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Ad

BHARGAVIARRAY.PPT.pptx

  • 1. ARRAYS IN C PRESENTED BY: Narra bhargavi 22AJ1A0562 CSE-A
  • 2. INTRODUCTION • We know the fundamental data types, namely char, int, float, double and it’s variations. • Although these types are very useful, the variable of these types can store only one value at a given time. • Therefore, these data types can be used only to handle limited amounts of data. • In many applications we need handle large volume of data for processing. • To process such large amounts of data we need a powerful data type.
  • 3. DEFINITION OF ARRAY • An array is a fixed–size sequenced collection of elements of same data type • In simplest form, an array can be used to represent a list of numbers, a list of names. • An array is a collection of similar data items, that are stored under a common name. • A value in an array is identified by index or subscript enclosed in square bracket with array name.
  • 4. FEATURES OF ARRAYS • An array is a derived data type. It is used to represent a collection of elements of the same data type. • The elements can be accessed with base address (index) and the subscript defined for the position of the element. • The elements in an array are stored in contiguous memory location. • It is easier to refer the array elements by simply incrementing the value of the subscript.
  • 5. TYPES OF ARRAYS 1. One dimensional array 2. Two dimensional array 3. Multidimensional array ONE DIMENSIONAL ARRAY The collection of data items can be stored under a variable name using only one subscript
  • 6. ARRAY DECLARATION The general form of array declaration is: data_type array_variable-name[size]; • Data_type – specifies the type of element that will be contained in the array , such as int, char • size –indicates the maximum number of elements that can be stored inside the array.
  • 7. EXAMPLE • For example we want to represent a set of five numbers, say (10,20,30,40,50) by an array variable number, then we may declare the variable number as follows int number[5]; • and the computer reserves five storage locations as shown below: Number[0] Number[1] Number[2] Number[3] Number[4]
  • 8. ARRAY INTIALIZATION Syntax: data_type array_variable-name[SIZE]={LIST OF VALUE} EXAMPLE : int number[5]={10,20,30,40,50}; Number[0] Number[1] Number[2] Number[3] Number[4] fv 10 20 30 40 50
  • 9. MORE EXAMPLES FOR ARRAY INITIALIZATION int counter[ ]= {10,20,30,40,50}; char name[ ]= { ’J’ , ’H’ , ’O’ , ’N’ , ’0” }; alternatively, char name[ ]= “john”; //array with string int number[5]={10,20}; number[0]=10,number[1]=20, number[2]=0,number[3]=0,number[4]=0 •we can also initialize an array with scanf() function. for example, int x[5]; printf(“enter the values:”); scanf(“%d%d%d”,&x[0],&x[1],&x[2]);
  • 10. EXAMPLE PROGRAM #include<stdio.h> #include<conio.h> void main() { int a[5],sum=0,i; printf(“Enter 5 numbers”); for(i=0;i<5;i++) { scanf(“%dn”,&a[i]); sum=sum+a[i]; } printf(“the sum of given numbers is : %dn”, sum); }
  • 11. TWO DIMENSIONAL ARRAY SYNTAX: data_type array_name [row-size][column-size]; INITIAZING TWO DIMENSIONAL ARRAY: Like one dimensional arrays, two dimensional arrays can be initialized by their declaration int table[2][3] = {0,0,0,1,1,1}; will assigns the values as follows, table[0][1]=0, table[0][1]=0, table[0][2]=0, table[1][0]=1, table[1][1]=1, table[1][2]=1 the above statement can be written as int table[2][3]={{0,0,0},{1,1,1}}; also int table[2][3] = { {0,0,0}, {1,1,1} };
  • 12. Example program #include <stdio.h> main() { int m, n, i, j, first[10][10], second[10][10], sum[10][10]; printf("Enter the number of rows and columns of matrix "); scanf("%d%d", &m, &n); printf("Enter the elements of first matrixn"); for ( i = 0 ; i< m ; i++ ) for ( j = 0 ; j < n ; j++ ) scanf("%d", &first[i][j]); printf("Enter the elements of second matrixn"); for ( i = 0 ; i < m ; i++ ) for ( j = 0 ; j < n ; j++ ) scanf("%d", &second[i][j]);
  • 13. for ( i= 0 ; i < m ; i++ ) for ( j = 0 ; j< n ; j++ ) sum[i][j] = first[i][j] + second[i][j]; printf("Sum of entered matrices:-n"); for ( i= 0 ; i< m ; i++ ) { for ( j = 0 ; j < n ; j++ ) printf("%dt", sum[i][j]); printf("n"); } return 0; }
  • 14. MULTI-DIMENSIONAL ARRAY C allows arrays of more-dimensions called multi- dimensional array. The general form of a multi-dimensional array is: Type array-name[s1][s2][s3]…..[sn] Where ‘s’ is the size of the dimension int survey[3][5][2]; float table[5][4][5][3];