SlideShare a Scribd company logo
3
Most read
7
Most read
13
Most read
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.

More Related Content

What's hot (20)

PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
DOC
Time and space complexity
Ankit Katiyar
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPTX
Arrays in c
Jeeva Nanthini
 
PPTX
Data structure array
MajidHamidAli
 
PPT
One dimensional 2
Rajendran
 
PPTX
Searching
Ashim Lamichhane
 
PPTX
Array in c programming
Mazharul Islam
 
PDF
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPTX
Stack and Queue
Apurbo Datta
 
PDF
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
PPTX
Linked List
Ashim Lamichhane
 
PPTX
Hashing In Data Structure
Meghaj Mallick
 
PPTX
Abstract Data Types
karthikeyanC40
 
PPTX
ARRAY
ayush raj
 
PPT
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
PPTX
2D Array
Ehatsham Riaz
 
PPTX
Sorting Algorithms
Pranay Neema
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Time and space complexity
Ankit Katiyar
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Arrays in c
Jeeva Nanthini
 
Data structure array
MajidHamidAli
 
One dimensional 2
Rajendran
 
Searching
Ashim Lamichhane
 
Array in c programming
Mazharul Islam
 
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Stack and Queue
Apurbo Datta
 
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
Linked List
Ashim Lamichhane
 
Hashing In Data Structure
Meghaj Mallick
 
Abstract Data Types
karthikeyanC40
 
ARRAY
ayush raj
 
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
2D Array
Ehatsham Riaz
 
Sorting Algorithms
Pranay Neema
 

Similar to Array (20)

PDF
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
PDF
Arrays
Steven Wallach
 
PPTX
Programming in c Arrays
janani thirupathi
 
PPTX
Chapter 13.pptx
AnisZahirahAzman
 
PPTX
Arrays & Strings
Munazza-Mah-Jabeen
 
PPT
Basics of Data structure using C describing basics concepts
shanthidl1
 
PPTX
Arrays.pptx
saimasiddique11
 
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
PPTX
Array
Anil Dutt
 
PPTX
Introduction to Array & Structure & Basic Algorithms.pptx
MrNikhilMohanShinde
 
PDF
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
PDF
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
PPTX
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
PPTX
array ppt of c programing language for exam
shimishtrivedi
 
PDF
Array
hjasjhd
 
PPTX
Arrays basics
sudhirvegad
 
PDF
Introduction to Arrays in C
Thesis Scientist Private Limited
 
PPTX
Programming in c arrays
Uma mohan
 
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
Programming in c Arrays
janani thirupathi
 
Chapter 13.pptx
AnisZahirahAzman
 
Arrays & Strings
Munazza-Mah-Jabeen
 
Basics of Data structure using C describing basics concepts
shanthidl1
 
Arrays.pptx
saimasiddique11
 
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
Array
Anil Dutt
 
Introduction to Array & Structure & Basic Algorithms.pptx
MrNikhilMohanShinde
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
array ppt of c programing language for exam
shimishtrivedi
 
Array
hjasjhd
 
Arrays basics
sudhirvegad
 
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Programming in c arrays
Uma mohan
 
Ad

Recently uploaded (20)

PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Tally software_Introduction_Presentation
AditiBansal54083
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Ad

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.