SlideShare una empresa de Scribd logo
1 de 13
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]);
}
Accessing Array Elements using for loop
 We can able to read from and write all elements into array at a time using for loop
 Loop counter variable of for loop is considered as index of array
 Entering (write ) Data into array using for loop
int a[5];
int i;
for(i=0 ; i<5 ; i++)
{
printf(“Enter element: ”);
scanf(“%d”,&a[i])
}
 Read Data from array using for loop
int i;
for(i=0 ; i<5 ; i++)
{
printf(“%d”,a[i]) ;
}

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Unit 1 array based implementation
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementation
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
Array in c
Array in cArray in c
Array in c
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
 
Array
ArrayArray
Array
 
Java arrays
Java arraysJava arrays
Java arrays
 
Array
ArrayArray
Array
 
Presentation of array
Presentation of arrayPresentation of array
Presentation of array
 
Pooja
PoojaPooja
Pooja
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Arraysincv109102017 180831194256
Arraysincv109102017 180831194256Arraysincv109102017 180831194256
Arraysincv109102017 180831194256
 
Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
 
Data structures and algorithms arrays
Data structures and algorithms   arraysData structures and algorithms   arrays
Data structures and algorithms arrays
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
12. arrays
12. arrays12. arrays
12. arrays
 
Arrays
ArraysArrays
Arrays
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 

Similar a Arrays accessing using for loops

array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 

Similar a Arrays accessing using for loops (20)

Arrays declartion and initialization
Arrays declartion and initializationArrays declartion and initialization
Arrays declartion and initialization
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Arrays
ArraysArrays
Arrays
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
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
 
Arrays
ArraysArrays
Arrays
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Arrays
ArraysArrays
Arrays
 
Cunit3.pdf
Cunit3.pdfCunit3.pdf
Cunit3.pdf
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Array
ArrayArray
Array
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
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
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Arrays in c v1 09102017
Arrays in c v1 09102017Arrays in c v1 09102017
Arrays in c v1 09102017
 

Más de sangrampatil81

Más de 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
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Último (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Arrays accessing using for loops

  • 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]); }
  • 12. Accessing Array Elements using for loop  We can able to read from and write all elements into array at a time using for loop  Loop counter variable of for loop is considered as index of array  Entering (write ) Data into array using for loop int a[5]; int i; for(i=0 ; i<5 ; i++) { printf(“Enter element: ”); scanf(“%d”,&a[i]) }
  • 13.  Read Data from array using for loop int i; for(i=0 ; i<5 ; i++) { printf(“%d”,a[i]) ; }