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

What's hot (20)

Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
structure and union
structure and unionstructure and union
structure and union
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
C++ string
C++ stringC++ string
C++ string
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
Constants in java
Constants in javaConstants in java
Constants in java
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Structure in c
Structure in cStructure in c
Structure in c
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 

Similar to Arrays in c language (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
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
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
 

More from tanmaymodi4

Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1tanmaymodi4
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c languagetanmaymodi4
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 
Structures in c language
Structures in c languageStructures in c language
Structures in c languagetanmaymodi4
 
Union in c language
Union  in c languageUnion  in c language
Union in c languagetanmaymodi4
 

More from tanmaymodi4 (11)

Cryptocurrency
CryptocurrencyCryptocurrency
Cryptocurrency
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Functions in c language
Functions in c language Functions 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 language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 

Recently uploaded

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

Arrays in c language

  • 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 {