SlideShare a Scribd company logo
10
Most read
11
Most read
14
Most read
ARRAYS IN C
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

What's hot (20)

PPT
structure and union
student
 
PPTX
Strings in C language
P M Patil
 
PPTX
What is identifier c programming
Rumman Ansari
 
PPTX
Structure in C
Kamal Acharya
 
PPTX
Structure in C language
CGC Technical campus,Mohali
 
PPT
Variables in C Programming
programming9
 
PPTX
Presentation on Function in C Programming
Shuvongkor Barman
 
PPT
Enumerated data types in C
Arpana shree
 
PPTX
Arrays in c
CHANDAN KUMAR
 
PDF
Array data structure
maamir farooq
 
PPTX
Union in C programming
Kamal Acharya
 
PPTX
Array in c++
Mahesha Mano
 
PPTX
Data types in python
RaginiJain21
 
PPTX
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
PPTX
Looping statements in C
Jeya Lakshmi
 
PPTX
Function C programming
Appili Vamsi Krishna
 
PPTX
Structures in c language
tanmaymodi4
 
PPTX
Dynamic memory allocation
Viji B
 
PDF
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
PPTX
Dynamic memory allocation in c
lavanya marichamy
 
structure and union
student
 
Strings in C language
P M Patil
 
What is identifier c programming
Rumman Ansari
 
Structure in C
Kamal Acharya
 
Structure in C language
CGC Technical campus,Mohali
 
Variables in C Programming
programming9
 
Presentation on Function in C Programming
Shuvongkor Barman
 
Enumerated data types in C
Arpana shree
 
Arrays in c
CHANDAN KUMAR
 
Array data structure
maamir farooq
 
Union in C programming
Kamal Acharya
 
Array in c++
Mahesha Mano
 
Data types in python
RaginiJain21
 
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Looping statements in C
Jeya Lakshmi
 
Function C programming
Appili Vamsi Krishna
 
Structures in c language
tanmaymodi4
 
Dynamic memory allocation
Viji B
 
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Dynamic memory allocation in c
lavanya marichamy
 

Similar to Arrays in c (20)

PPTX
BHARGAVIARRAY.PPT.pptx
Sasideepa
 
PPTX
Arrays in Data Structure and Algorithm
KristinaBorooah
 
PPT
uderstanding arrays and how to declare arrays
ShirishaBuduputi
 
PDF
array-191103180006.pdf
HEMAHEMS5
 
PPTX
Presentation on array
topu93
 
PPTX
lec 2- array declaration and initialization.pptx
shiks1234
 
PPTX
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
PPTX
Array
PreethyJemima
 
PPT
Arrays
swathi reddy
 
PDF
Introduction to Arrays in C
Thesis Scientist Private Limited
 
DOCX
arrays.docx
lakshmanarao027MVGRC
 
DOC
Arrays and Strings
Dr.Subha Krishna
 
PPTX
Array in c
Harsh Bhanushali
 
PPT
Lecture 15 - Array
Md. Imran Hossain Showrov
 
PDF
Chapter 4 (Part I) - Array and Strings.pdf
KirubelWondwoson1
 
PDF
Arrays in C++
Maliha Mehr
 
PPTX
Arrays.pptx
Mohit750936
 
PPTX
ARRAYS.pptx
MamataAnilgod
 
PPTX
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
BHARGAVIARRAY.PPT.pptx
Sasideepa
 
Arrays in Data Structure and Algorithm
KristinaBorooah
 
uderstanding arrays and how to declare arrays
ShirishaBuduputi
 
array-191103180006.pdf
HEMAHEMS5
 
Presentation on array
topu93
 
lec 2- array declaration and initialization.pptx
shiks1234
 
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
Arrays
swathi reddy
 
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Arrays and Strings
Dr.Subha Krishna
 
Array in c
Harsh Bhanushali
 
Lecture 15 - Array
Md. Imran Hossain Showrov
 
Chapter 4 (Part I) - Array and Strings.pdf
KirubelWondwoson1
 
Arrays in C++
Maliha Mehr
 
Arrays.pptx
Mohit750936
 
ARRAYS.pptx
MamataAnilgod
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
Ad

Recently uploaded (20)

PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PDF
Novus Safe Lite- What is Novus Safe Lite.pdf
Novus Hi-Tech
 
PDF
HydITEx corporation Booklet 2025 English
Георгий Феодориди
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Shuen Mei Parth Sharma Boost Productivity, Innovation and Efficiency wit...
AWS Chicago
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PDF
HR agent at Mediq: Lessons learned on Agent Builder & Maestro by Tacstone Tec...
UiPathCommunity
 
PPTX
The Yotta x CloudStack Advantage: Scalable, India-First Cloud
ShapeBlue
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Bitcoin+ Escalando sin concesiones - Parte 1
Fernando Paredes García
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
Novus Safe Lite- What is Novus Safe Lite.pdf
Novus Hi-Tech
 
HydITEx corporation Booklet 2025 English
Георгий Феодориди
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Shuen Mei Parth Sharma Boost Productivity, Innovation and Efficiency wit...
AWS Chicago
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
HR agent at Mediq: Lessons learned on Agent Builder & Maestro by Tacstone Tec...
UiPathCommunity
 
The Yotta x CloudStack Advantage: Scalable, India-First Cloud
ShapeBlue
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Bitcoin+ Escalando sin concesiones - Parte 1
Fernando Paredes García
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Ad

Arrays in c

  • 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];