SlideShare a Scribd company logo
1 of 11
Arrays
Prepared By: Mr. Sangram A. Patil
Assistant Professor PVPIT,Budhgaon
Need of an Array
 Till now, we have been storing data in simple variables.
 Although storing data of a large number of people is quite difficult with the process
we use still.
 To store this large data, the developers developed the concept of arrays in C
language
void main()
{
int rollno=1;
int rollno=2;
int rollno1=3;
}
Introduction
 An array is a collection of similar data elements with same data type
 The elements of the array are stored in consecutive memory locations and
are referenced by an index.
 Index indicates an ordinal number of the elements counted from beginning of the array.
Properties of Array
 The array contains the following properties.
 Each element of an array is of same data type and carries the same size, i.e., int = 2
bytes.
 Elements of the array are stored at contiguous memory locations where the first
element is stored at the smallest memory location.
 Elements of the array can be randomly accessed since we can calculate the address
of each element of the array with the given base address and the size of the data
element.
Advantage of C Array
1) Code Optimization: Less code to the access the data.
2) Ease of traversing: By using the for loop, we can retrieve the elements of an array
easily.
3) Ease of sorting: To sort the elements of the 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 the array, we can't
exceed the limit. So, it doesn't grow the size dynamically like LinkedList
 Arrays are of three types :
 Single dimensional Array
 Two-dimensional Array
 Multi-dimensional Array
Single dimensional Array
 The one dimensional array or single dimensional array in C language is the simplest
type of array that contains only one row for storing data.
 One dimensional array is like a list of some items, which can be stored by
using only one dimension
Declaration of Array
 An array must be declared before being used
 Declaring an array means specifying three things
1. Data type-what kind of values it can store, like int, char, float, double
2. Name-to identify the array
3. Size-the maximum number of values that array can hold
Syntax :
datatype array_name[ size ];
Ex :
int rollno[10];
float marks[10];
Initialization of Arrays
 Elements of the array can also be initialized at the time of declaration as in the case
of every variable.
 Arrays are initialized as :
datatype array_name[size]={list of values};
 Ex :
int a[5]={90,82,78,95,88};
a[0] a[1] a[2] a[3] a[4]
90 82 78 95 88
Accessing Array Elements
 An element is accessed by indexing the array name. This is done by placing the index of
the element within square brackets after the name of the array.
Void main()
{
int a[5]={90,82,78,95,88};
printf(“value at a[0]: %d”,a[0]);
printf(“value at a[0]: %d”,a[1]);
printf(“value at a[0]: %d”,a[4]);
printf(“value at a[0]: %d”,a[3]);
}

More Related Content

What's hot

Unit 1 array based implementation
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementationLavanyaJ28
 
Concepts of Arrays
Concepts of ArraysConcepts of Arrays
Concepts of ArraysYashh Pandya
 
Types of Arrays
Types of ArraysTypes of Arrays
Types of ArraysAns Ali
 
September 9 2008
September 9 2008September 9 2008
September 9 2008napzpogi
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2Self-Employed
 
Dynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDeepam Aggarwal
 
R data-structures-3
R data-structures-3R data-structures-3
R data-structures-3Victor Ordu
 
R Data Structures (Part 1)
R Data Structures (Part 1)R Data Structures (Part 1)
R Data Structures (Part 1)Victor Ordu
 
R data structures-2
R data structures-2R data structures-2
R data structures-2Victor Ordu
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesHoang Nguyen
 
Array c programming
Array c programmingArray c programming
Array c programmingDevan Thakur
 

What's hot (19)

Unit 1 array based implementation
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementation
 
Data structure
Data structureData structure
Data structure
 
Concepts of Arrays
Concepts of ArraysConcepts of Arrays
Concepts of Arrays
 
Types of Arrays
Types of ArraysTypes of Arrays
Types of Arrays
 
September 9 2008
September 9 2008September 9 2008
September 9 2008
 
Lesson 11 one dimensional array
Lesson 11 one dimensional arrayLesson 11 one dimensional array
Lesson 11 one dimensional array
 
C
CC
C
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
Ppt lesson 12
Ppt lesson 12Ppt lesson 12
Ppt lesson 12
 
Dynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDynamic memory allocation and linked lists
Dynamic memory allocation and linked lists
 
Matlab Organizing Data
Matlab Organizing DataMatlab Organizing Data
Matlab Organizing Data
 
7.basic array
7.basic array7.basic array
7.basic array
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
R data-structures-3
R data-structures-3R data-structures-3
R data-structures-3
 
R Data Structures (Part 1)
R Data Structures (Part 1)R Data Structures (Part 1)
R Data Structures (Part 1)
 
R data structures-2
R data structures-2R data structures-2
R data structures-2
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Loops and arrays
Loops and arraysLoops and arrays
Loops and arrays
 
Array c programming
Array c programmingArray c programming
Array c programming
 

Similar to Arrays declartion and initialization

Similar to Arrays declartion and initialization (20)

Arrays
ArraysArrays
Arrays
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Array
ArrayArray
Array
 
12000121037.pdf
12000121037.pdf12000121037.pdf
12000121037.pdf
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Arrays
ArraysArrays
Arrays
 
Arrays in c_language
Arrays in c_language Arrays in c_language
Arrays in c_language
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Chapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdfChapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdf
 
Cunit3.pdf
Cunit3.pdfCunit3.pdf
Cunit3.pdf
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
ARRAY.pptx
ARRAY.pptxARRAY.pptx
ARRAY.pptx
 
Pooja
PoojaPooja
Pooja
 
Pooja
PoojaPooja
Pooja
 

More from sangrampatil81

More from sangrampatil81 (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
IO hardware
IO hardwareIO hardware
IO hardware
 
File system structure
File system structureFile system structure
File system structure
 
File management
File managementFile management
File management
 
Disk structure
Disk structureDisk structure
Disk structure
 
Directory structure
Directory structureDirectory structure
Directory structure
 
Directory implementation and allocation methods
Directory implementation and allocation methodsDirectory implementation and allocation methods
Directory implementation and allocation methods
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Monitors
MonitorsMonitors
Monitors
 
Classical problems of process synchronization
Classical problems of process synchronizationClassical problems of process synchronization
Classical problems of process synchronization
 
System programs
System programsSystem programs
System programs
 
System programs
System programsSystem programs
System programs
 
Services and system calls
Services and system callsServices and system calls
Services and system calls
 
Operating system structure
Operating system structureOperating system structure
Operating system structure
 
Operating system deign and implementation
Operating system deign and implementationOperating system deign and implementation
Operating system deign and implementation
 
Pointer to array and structure
Pointer to array and structurePointer to array and structure
Pointer to array and structure
 

Recently uploaded

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 

Arrays declartion and initialization

  • 1. Arrays Prepared By: Mr. Sangram A. Patil Assistant Professor PVPIT,Budhgaon
  • 2. Need of an Array  Till now, we have been storing data in simple variables.  Although storing data of a large number of people is quite difficult with the process we use still.  To store this large data, the developers developed the concept of arrays in C language void main() { int rollno=1; int rollno=2; int rollno1=3; }
  • 3. Introduction  An array is a collection of similar data elements with same data type  The elements of the array are stored in consecutive memory locations and are referenced by an index.  Index indicates an ordinal number of the elements counted from beginning of the array.
  • 4. Properties of Array  The array contains the following properties.  Each element of an array is of same data type and carries the same size, i.e., int = 2 bytes.  Elements of the array are stored at contiguous memory locations where the first element is stored at the smallest memory location.  Elements of the array can be randomly accessed since we can calculate the address of each element of the array with the given base address and the size of the data element.
  • 5. Advantage of C Array 1) Code Optimization: Less code to the access the data. 2) Ease of traversing: By using the for loop, we can retrieve the elements of an array easily. 3) Ease of sorting: To sort the elements of the array, we need a few lines of code only. 4) Random Access: We can access any element randomly using the array.
  • 6. Disadvantage of C Array 1) Fixed Size: Whatever size, we define at the time of declaration of the array, we can't exceed the limit. So, it doesn't grow the size dynamically like LinkedList
  • 7.  Arrays are of three types :  Single dimensional Array  Two-dimensional Array  Multi-dimensional Array
  • 8. Single dimensional Array  The one dimensional array or single dimensional array in C language is the simplest type of array that contains only one row for storing data.  One dimensional array is like a list of some items, which can be stored by using only one dimension
  • 9. Declaration of Array  An array must be declared before being used  Declaring an array means specifying three things 1. Data type-what kind of values it can store, like int, char, float, double 2. Name-to identify the array 3. Size-the maximum number of values that array can hold Syntax : datatype array_name[ size ]; Ex : int rollno[10]; float marks[10];
  • 10. Initialization of Arrays  Elements of the array can also be initialized at the time of declaration as in the case of every variable.  Arrays are initialized as : datatype array_name[size]={list of values};  Ex : int a[5]={90,82,78,95,88}; a[0] a[1] a[2] a[3] a[4] 90 82 78 95 88
  • 11. Accessing Array Elements  An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array. Void main() { int a[5]={90,82,78,95,88}; printf(“value at a[0]: %d”,a[0]); printf(“value at a[0]: %d”,a[1]); printf(“value at a[0]: %d”,a[4]); printf(“value at a[0]: %d”,a[3]); }