SlideShare ist ein Scribd-Unternehmen logo
1 von 17
ARRAY
Data Structure Presented by
Harsh Kumar(191020426)
Santosh Tigga(191020448)
Title and
Content
Layout
with List
Arrays
Multidimensional Arrays
Arrays & Function
Arrays and Pointers
C Arrays
• An array is a variable that can store multiple values. For
example, if you want to store 100 integers, you can create an
array for it.
• int data[100];
How to
declare an
array?
• datatype array Name[array Size];
• For example,
• float mark[5];
• Here, we declared an array, mark, of
floating-point type. And its size is 5.
Meaning, it can hold 5 floating-point
values.
• It's important to note that the size and
type of an array cannot be changed
once it is declared.
Access Array
Elements
• You can access elements of an array by indices.
• Suppose you declared an array mark as above. The first
element is mark[0], the second element is mark[1] and so
on.
Few keynotes:
• Arrays have 0 as the first index, not 1. In this example, mark[0] is the
first element.
• If the size of an array is n, to access the last element, the n-1 index is
used. In this example, mark[4]
• Suppose the starting address of mark[0] is 2120d. Then, the address of
the mark[1] will be 2124d. Similarly, the address of mark[2] will
be 2128d and so on.
This is because the size of a float is 4 bytes.
How to initialize an array?
• It is possible to initialize an array during declaration. For example,
• int mark[5] = {19, 10, 8, 17, 9};
• You can also initialize an array like this.
• int mark[] = {19, 10, 8, 17, 9};
• Here, we haven't specified the size. However, the compiler knows its
size is 5 as we are initializing it with 5 elements.
Here,
mark[0] is equal to 19
mark[1] is equal to 10
mark[2] is equal to 8
mark[3] is equal to 17
mark[4] is equal to 9
Change
Value of
Array
elements
• int mark[5] = {19, 10, 8, 17, 9}
•
• // make the value of the third element
to -1
• mark[2] = -1;
•
• // make the value of the fifth element to
0
• mark[4] = 0;
Input and
Output
Array
Elements
• Here's how you can take input from the
user and store it in an array element.
• // take input and store it in the 3rd
element
• ​scan("%d", &mark[2]);
•
• // take input and store it in the ith
element
• scan("%d", &mark[i-1]);
Here's how you
can print an
individual
element of an
array.
• // print the first element of the array
• printf("%d", mark[0]);
•
• // print the third element of the array
• printf("%d", mark[2]);
•
• // print ith element of the array
• printf("%d", mark[i-1]);
Access elements out of its bound!
• Suppose you declared an array of 10 elements. Let's say,
• int testArray[10];
• You can access the array elements from test Array[0] to test Array[9].
• Now let's say if you try to access testArray[12]. The element is not
available. This may cause unexpected output (undefined behavior).
Sometimes you might get an error and some other time your program
may run correctly.
• Hence, you should never access elements of an array outside of its
bound.
C Multidimensio
nal Arrays
• In C programming, you can create an array of
arrays. These arrays are known as multidimensional
arrays. For example,
• float x[3][4];
• Here, x is a two-dimensional (2d) array. The array
can hold 12 elements. You can think the array as a
table with 3 rows and each row has 4 columns.
•
Similarly, you can declare a three-dimensional (3d)
array. For example,
• float y[2][4][3];
• Here, the array y can hold 24 elements.
Initializing a multidimensional array
Initialization of a 2d
array
• // Different ways to initialize two-
dimensional array
•
• int c[2][3] = {{1, 3, 0}, {-1, 5, 9}};
•
• int c[][3] = {{1, 3, 0}, {-1, 5, 9}};
•
• int c[2][3] = {1, 3, 0, -1, 5, 9};
Initialization of a 3d
array
• int test[2][3][4] = {
• {{3, 4, 2, 3}, {0, -3, 9, 11}, {23, 12, 23,
2}},
• {{13, 4, 56, 3}, {5, 9, 3, 5}, {3, 1, 4,
9}}};
Pass
arrays to a
function
in C
• Passing array elements to a function is
similar to passing variables to a
function.
• To pass multidimensional arrays to a
function, only the name of the array is
passed to the function(similar to one-
dimensional arrays).
Relationshi
p Between
Arrays and
Pointers
• Array in C is used to store elements of
same types whereas Pointers are
address variables which stores the
address of a variable.
Now array variable is also having a
address which can be pointed by
a pointer and array can be navigated
using pointer.
This Photo by Unknown author is licensed under CC BY-SA-NC.

Weitere ähnliche Inhalte

Was ist angesagt?

Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 

Was ist angesagt? (20)

Array ppt
Array pptArray ppt
Array ppt
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
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
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Array data structure
Array data structureArray data structure
Array data structure
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in C
Array in CArray in C
Array in C
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
ARRAY
ARRAYARRAY
ARRAY
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Structure in C
Structure in CStructure in C
Structure in C
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 

Ähnlich wie Array

Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
dfsdg3
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
MrNikhilMohanShinde
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
martha leon
 

Ähnlich wie Array (20)

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
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
7array in c#
7array in c#7array in c#
7array in c#
 
Arrays
ArraysArrays
Arrays
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Introduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptxIntroduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
CHAPTER-5.ppt
CHAPTER-5.pptCHAPTER-5.ppt
CHAPTER-5.ppt
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
PPt. on An _Array in C
PPt. on An _Array in CPPt. on An _Array in C
PPt. on An _Array in C
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 

Kürzlich hochgeladen

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

Kürzlich hochgeladen (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
+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...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
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
 
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
 
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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
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...
 
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
 
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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.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
 
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 ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Array

  • 1. ARRAY Data Structure Presented by Harsh Kumar(191020426) Santosh Tigga(191020448)
  • 2. Title and Content Layout with List Arrays Multidimensional Arrays Arrays & Function Arrays and Pointers
  • 3. C Arrays • An array is a variable that can store multiple values. For example, if you want to store 100 integers, you can create an array for it. • int data[100];
  • 4. How to declare an array? • datatype array Name[array Size]; • For example, • float mark[5]; • Here, we declared an array, mark, of floating-point type. And its size is 5. Meaning, it can hold 5 floating-point values. • It's important to note that the size and type of an array cannot be changed once it is declared.
  • 5. Access Array Elements • You can access elements of an array by indices. • Suppose you declared an array mark as above. The first element is mark[0], the second element is mark[1] and so on.
  • 6. Few keynotes: • Arrays have 0 as the first index, not 1. In this example, mark[0] is the first element. • If the size of an array is n, to access the last element, the n-1 index is used. In this example, mark[4] • Suppose the starting address of mark[0] is 2120d. Then, the address of the mark[1] will be 2124d. Similarly, the address of mark[2] will be 2128d and so on. This is because the size of a float is 4 bytes.
  • 7. How to initialize an array? • It is possible to initialize an array during declaration. For example, • int mark[5] = {19, 10, 8, 17, 9}; • You can also initialize an array like this. • int mark[] = {19, 10, 8, 17, 9}; • Here, we haven't specified the size. However, the compiler knows its size is 5 as we are initializing it with 5 elements.
  • 8. Here, mark[0] is equal to 19 mark[1] is equal to 10 mark[2] is equal to 8 mark[3] is equal to 17 mark[4] is equal to 9
  • 9. Change Value of Array elements • int mark[5] = {19, 10, 8, 17, 9} • • // make the value of the third element to -1 • mark[2] = -1; • • // make the value of the fifth element to 0 • mark[4] = 0;
  • 10. Input and Output Array Elements • Here's how you can take input from the user and store it in an array element. • // take input and store it in the 3rd element • ​scan("%d", &mark[2]); • • // take input and store it in the ith element • scan("%d", &mark[i-1]);
  • 11. Here's how you can print an individual element of an array. • // print the first element of the array • printf("%d", mark[0]); • • // print the third element of the array • printf("%d", mark[2]); • • // print ith element of the array • printf("%d", mark[i-1]);
  • 12. Access elements out of its bound! • Suppose you declared an array of 10 elements. Let's say, • int testArray[10]; • You can access the array elements from test Array[0] to test Array[9]. • Now let's say if you try to access testArray[12]. The element is not available. This may cause unexpected output (undefined behavior). Sometimes you might get an error and some other time your program may run correctly. • Hence, you should never access elements of an array outside of its bound.
  • 13. C Multidimensio nal Arrays • In C programming, you can create an array of arrays. These arrays are known as multidimensional arrays. For example, • float x[3][4]; • Here, x is a two-dimensional (2d) array. The array can hold 12 elements. You can think the array as a table with 3 rows and each row has 4 columns. • Similarly, you can declare a three-dimensional (3d) array. For example, • float y[2][4][3]; • Here, the array y can hold 24 elements.
  • 14. Initializing a multidimensional array Initialization of a 2d array • // Different ways to initialize two- dimensional array • • int c[2][3] = {{1, 3, 0}, {-1, 5, 9}}; • • int c[][3] = {{1, 3, 0}, {-1, 5, 9}}; • • int c[2][3] = {1, 3, 0, -1, 5, 9}; Initialization of a 3d array • int test[2][3][4] = { • {{3, 4, 2, 3}, {0, -3, 9, 11}, {23, 12, 23, 2}}, • {{13, 4, 56, 3}, {5, 9, 3, 5}, {3, 1, 4, 9}}};
  • 15. Pass arrays to a function in C • Passing array elements to a function is similar to passing variables to a function. • To pass multidimensional arrays to a function, only the name of the array is passed to the function(similar to one- dimensional arrays).
  • 16. Relationshi p Between Arrays and Pointers • Array in C is used to store elements of same types whereas Pointers are address variables which stores the address of a variable. Now array variable is also having a address which can be pointed by a pointer and array can be navigated using pointer.
  • 17. This Photo by Unknown author is licensed under CC BY-SA-NC.