SlideShare a Scribd company logo
1 of 18
Arrays In C
Definition
 An array is a data structure which
stores homogeneous(similar)data
items.
 An array variable is used to store
more than one data item of same data
type at contiguous memory locations.
Example:
 C array is beneficial if you have to store
similar elements.
 Suppose you have to store marks of 50
students, one way to do this is allotting 50
variables.
 So it will be typical and hard to manage.
For example we can not access the value
of these variables with only 1 or 2 lines of
code.
 Another way to do this is array. By using
array, we can access the elements easily.
Only few lines of code is required to
access the elements of array.
Advantage of C Array
1) Code Optimization: Less code to
the access the data.
2) Easy to traverse data: By using the
for loop, we can retrieve the elements
of an array easily.
3) Easy to sort data: To sort the
elements of array, we need a few lines
of code only.
4) Random Access: We can access
any element randomly using the array.
Disadvantage of C Array
1) Fixed Size: Whatever size, we define
at the time of declaration of array, we
can't exceed the limit. So, it doesn't
grow the size dynamically like
LinkedList
Array Terminology
Array variable is composed with the following
terms:
 Size:total number of elements in an array
 Type: data type of declared array.
 Base:address of the first element of the
array.
 Index:Location or index value of array
element.
 Range:Value from lower bound to upper
bound.
 Word:indicates the space required for an
element.
Declaration of C Array
when array size is given:
 We can declare an array in the c
language in the following way:
 the example to declare array:
 Here, int is the data_type, marks is
the array_name and 5 is
the array_size.
Declaration of C Array
when array size is not known before
compilation:
data type array_name [];
//size will depend upon the elements
entered by user at run time.
Example:
int a[];
Initialization of C Array
At the time of declaration:
 A simple way to initialize array is by
index.
 array index starts from 0 and ends
with [SIZE - 1].
 int
a[5]={10,20,30,40,50}
Taking input from the user:
void main()
{
int a[5];
for(int i=0;i<5;i++)
{ to take input
printf(“enter the array element”); from the
user
scanf(“%d”,&a[i]);
}
for(int i=0;i<5;i++)
{ to display
output
printf(“the array is: %d”,a[i]); to the user
}
}
C array example
C Array: Declaration with
Initialization
 We can initialize the c array at the
time of declaration.
 In such case, there is no requirement
to define size. So it can also be
written as the following code.
C array example:
Two dimensional Array
 The two dimensional array in C
language is represented in the form of
rows and columns, also known as
matrix.
 It is also known as array of
arrays or list of arrays.
 The two dimensional, three
dimensional or other dimensional
arrays are also known
as multidimensional arrays.
Declaration of two dimensional
Array in C
 We can declare an array in the C
language in the following way:
 A simple example to declare two
dimensional array:
 Here, 4 is the row number and 3 is
the column number.
Initialization of 2D Array in C
While declaring it:
Taking input from the user:
Two dimensional array example
in C
int a[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
printf(“enter the arary”); Taking input
scanf(“%d”,&a[i][j]);
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++) Giving output
{

More Related Content

What's hot (20)

Array in c
Array in cArray in c
Array in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in c
Array in cArray in c
Array in c
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
 
arrays in c
arrays in carrays in c
arrays in c
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Array
ArrayArray
Array
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Array C programming
Array C programmingArray C programming
Array C programming
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays
ArraysArrays
Arrays
 
Array in c++
Array in c++Array in c++
Array in c++
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 

Similar to Arrays in c v1 09102017

Similar to Arrays in c v1 09102017 (20)

Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Cunit3.pdf
Cunit3.pdfCunit3.pdf
Cunit3.pdf
 
Break and continue in C
Break and continue in C Break and continue in C
Break and continue in C
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loops
 
C# Array.pptx
C# Array.pptxC# Array.pptx
C# Array.pptx
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Arrays
ArraysArrays
Arrays
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Break and Continue Statement in C Programming
Break and Continue Statement in C ProgrammingBreak and Continue Statement in C Programming
Break and Continue Statement in C Programming
 

More from Tanmay Modi

Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguageTanmay Modi
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c languageTanmay Modi
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
Generations of computers
Generations of computersGenerations of computers
Generations of computersTanmay Modi
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languageTanmay Modi
 
Union in c language
Union in c languageUnion in c language
Union in c languageTanmay Modi
 
Structures in c language
Structures in c languageStructures in c language
Structures in c languageTanmay Modi
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c languageTanmay Modi
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c languageTanmay Modi
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 

More from Tanmay Modi (12)

Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Generations of computers
Generations of computersGenerations of computers
Generations of computers
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Union in c language
Union in c languageUnion in c language
Union in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c language
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Cryptocurrency
Cryptocurrency Cryptocurrency
Cryptocurrency
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Arrays in c v1 09102017

  • 2. Definition  An array is a data structure which stores homogeneous(similar)data items.  An array variable is used to store more than one data item of same data type at contiguous memory locations.
  • 3. Example:  C array is beneficial if you have to store similar elements.  Suppose you have to store marks of 50 students, one way to do this is allotting 50 variables.  So it will be typical and hard to manage. For example we can not access the value of these variables with only 1 or 2 lines of code.  Another way to do this is array. By using array, we can access the elements easily. Only few lines of code is required to access the elements of array.
  • 4. Advantage of C Array 1) Code Optimization: Less code to the access the data. 2) Easy to traverse data: By using the for loop, we can retrieve the elements of an array easily. 3) Easy to sort data: To sort the elements of array, we need a few lines of code only. 4) Random Access: We can access any element randomly using the array.
  • 5. Disadvantage of C Array 1) Fixed Size: Whatever size, we define at the time of declaration of array, we can't exceed the limit. So, it doesn't grow the size dynamically like LinkedList
  • 6. Array Terminology Array variable is composed with the following terms:  Size:total number of elements in an array  Type: data type of declared array.  Base:address of the first element of the array.  Index:Location or index value of array element.  Range:Value from lower bound to upper bound.  Word:indicates the space required for an element.
  • 7. Declaration of C Array when array size is given:  We can declare an array in the c language in the following way:  the example to declare array:  Here, int is the data_type, marks is the array_name and 5 is the array_size.
  • 8. Declaration of C Array when array size is not known before compilation: data type array_name []; //size will depend upon the elements entered by user at run time. Example: int a[];
  • 9. Initialization of C Array At the time of declaration:  A simple way to initialize array is by index.  array index starts from 0 and ends with [SIZE - 1].  int a[5]={10,20,30,40,50}
  • 10. Taking input from the user: void main() { int a[5]; for(int i=0;i<5;i++) { to take input printf(“enter the array element”); from the user scanf(“%d”,&a[i]); } for(int i=0;i<5;i++) { to display output printf(“the array is: %d”,a[i]); to the user } }
  • 12. C Array: Declaration with Initialization  We can initialize the c array at the time of declaration.  In such case, there is no requirement to define size. So it can also be written as the following code.
  • 14. Two dimensional Array  The two dimensional array in C language is represented in the form of rows and columns, also known as matrix.  It is also known as array of arrays or list of arrays.  The two dimensional, three dimensional or other dimensional arrays are also known as multidimensional arrays.
  • 15. Declaration of two dimensional Array in C  We can declare an array in the C language in the following way:  A simple example to declare two dimensional array:  Here, 4 is the row number and 3 is the column number.
  • 16. Initialization of 2D Array in C While declaring it: Taking input from the user:
  • 17. Two dimensional array example in C
  • 18. int a[3][3]; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { printf(“enter the arary”); Taking input scanf(“%d”,&a[i][j]); } } for(int i=0;i<3;i++) { for(int j=0;j<3;j++) Giving output {