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)

PPTX
Union in C programming
Kamal Acharya
 
PPTX
Arrays
Trupti Agrawal
 
PPTX
Introduction to Array ppt
sandhya yadav
 
PPT
structure and union
student
 
PPTX
Array in C
Kamal Acharya
 
PPTX
Data types in C language
kashyap399
 
PPTX
Array Of Pointers
Sharad Dubey
 
PPTX
Strings in C language
P M Patil
 
PPTX
Structure in C
Kamal Acharya
 
PPTX
class and objects
Payel Guria
 
PPTX
concept of Array, 1D & 2D array
Sangani Ankur
 
PPT
Structure in c
Prabhu Govind
 
PPTX
Tokens in C++
Mahender Boda
 
PPTX
Constructors and Destructor in C++
International Institute of Information Technology (I²IT)
 
PPTX
sorting and its types
SIVASHANKARIRAJAN
 
PPTX
Data types in C
Tarun Sharma
 
PPTX
Inheritance in c++
Vineeta Garg
 
PPTX
data types in C programming
Harshita Yadav
 
PPTX
Array in c++
Mahesha Mano
 
PPT
Pointers C programming
Appili Vamsi Krishna
 
Union in C programming
Kamal Acharya
 
Introduction to Array ppt
sandhya yadav
 
structure and union
student
 
Array in C
Kamal Acharya
 
Data types in C language
kashyap399
 
Array Of Pointers
Sharad Dubey
 
Strings in C language
P M Patil
 
Structure in C
Kamal Acharya
 
class and objects
Payel Guria
 
concept of Array, 1D & 2D array
Sangani Ankur
 
Structure in c
Prabhu Govind
 
Tokens in C++
Mahender Boda
 
sorting and its types
SIVASHANKARIRAJAN
 
Data types in C
Tarun Sharma
 
Inheritance in c++
Vineeta Garg
 
data types in C programming
Harshita Yadav
 
Array in c++
Mahesha Mano
 
Pointers C programming
Appili Vamsi Krishna
 

Similar to Arrays in c (20)

PPTX
BHARGAVIARRAY.PPT.pptx
Sasideepa
 
PPTX
Arrays basics
sudhirvegad
 
PDF
Arrays-Computer programming
nmahi96
 
PDF
Array
hjasjhd
 
PDF
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
PPTX
Chapter 13.pptx
AnisZahirahAzman
 
PDF
Arrays
Steven Wallach
 
PDF
Introduction to Arrays in C
Thesis Scientist Private Limited
 
PPTX
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
PPTX
Basic array in c programming
Sajid Hasan
 
PPTX
Array.pptx
fixocin377
 
PPTX
Arrays & Strings
Munazza-Mah-Jabeen
 
PPT
Arrays
swathi reddy
 
PPTX
Array ppt you can learn in very few slides.
dwivedyp
 
PPTX
Arrays In C Language
Surbhi Yadav
 
PPTX
ARRAYS IN C.pptx
Liga8
 
PPTX
Arrays in C language
Shubham Sharma
 
PDF
Array&amp;string
chanchal ghosh
 
BHARGAVIARRAY.PPT.pptx
Sasideepa
 
Arrays basics
sudhirvegad
 
Arrays-Computer programming
nmahi96
 
Array
hjasjhd
 
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
Chapter 13.pptx
AnisZahirahAzman
 
Introduction to Arrays in C
Thesis Scientist Private Limited
 
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
Basic array in c programming
Sajid Hasan
 
Array.pptx
fixocin377
 
Arrays & Strings
Munazza-Mah-Jabeen
 
Arrays
swathi reddy
 
Array ppt you can learn in very few slides.
dwivedyp
 
Arrays In C Language
Surbhi Yadav
 
ARRAYS IN C.pptx
Liga8
 
Arrays in C language
Shubham Sharma
 
Array&amp;string
chanchal ghosh
 
Ad

Recently uploaded (20)

PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
The Future of Artificial Intelligence (AI)
Mukul
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
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];