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

structure and union
structure and unionstructure and union
structure and union
student
 

What's hot (20)

Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Data types in java
Data types in javaData types in java
Data types in java
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
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
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
2D Array
2D Array 2D Array
2D Array
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
structure and union
structure and unionstructure and union
structure and union
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Array in c
Array in cArray in c
Array in c
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 

Similar to Arrays in c language

Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
dfsdg3
 

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
 
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 tanmaymodi4

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

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
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

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 {