SlideShare a Scribd company logo
1 of 16
Arrays
• An array is defined as the collection of similar
type of data items stored at contiguous
memory locations.
• Arrays are the derived data type in C
programming language which can store the
primitive type of data such as int, char,
double, float, etc.
• C array is beneficial if you have to store similar
elements. For example, if we want to store the
marks of a student in 6 subjects, then we
don't need to define different variables for the
marks in the different subject.
• Instead of that, we can define an array which
can store the marks in each subject at the
contiguous memory locations.
Properties of Array
• Each element of an array is of same data type
and carries the same size, i.e., int = 4 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
Declaration of C Array
• data_type array_name[array_size];
• Example:
• int marks[5];
Initialization of C Array
• marks[0]=80;//initialization of array
• marks[1]=60;
• marks[2]=70;
• marks[3]=85;
• marks[4]=75;
Types of array
• One dimensional array: A one dimensional array
is a linear list consisting of related and similar
data items (or) only one subscripted array is
called as one or single dimensional arrays.
• Declaration and initialization of one dimensional
array:
• Array initialization in compile time
• int a[10]={10,20,30,40,50};
• one subscript
• Two Dimensional Arrays: Storing or
representing the data in two dimensional that
is in tabular form (or) two subscripted array is
called two dimensional array.
• It is also known as a matrix.
• Syntax: Data-type variable name [number of
rows][number of columns];
• Example: int a [3][4];
• Initialization:-
• int a[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};
A 2D array’s elements are stored in continuous
memory locations. It can be represented in
memory using any of the following two ways:
1. Column-Major Order
2. Row-Major Order
1. Column-Major Order:
In this method the elements are stored column
wise, i.e. n elements of first column are stored in
first n locations, n elements of second column are
stored in next n locations and so on.
• 2. Row-Major Order:
In this method the elements are stored row wise, i.e.
m elements of first row are stored in first m
locations, m elements of second row are stored in
next m locations and so on.
• The array that we have in the example below is
having the dimensions 5 and 4.
• These dimensions are known as subscripts. So this
array has first subscript value as 5 and second
subscript value as 4.
• So the array abc[5][4] can have 5*4 = 20 elements.
Multidimensional arrays
• A multi-dimensional array is an array that has
more than one dimension.
• It is an array of arrays; an array that has
multiple levels.
• The simplest multi-dimensional array is the 2D
array, or two-dimensional array.
• C allows arrays of three or more dimensions.
• The general form of a multi-dimensional array is
• Syntax:
• data_type
array_name[block_size][row_size][column_size];
• Example: int a[2][3][3];
•
int a[2][3][3];
//array of type integer
//number of blocks of 2D arrays:2 |rows:3 |columns:3
//number of elements:2*3*3=18 integer elements
can be stored.
block(1) 11 22 33 block(2) 12 13 14
44 55 66 21 31 41
77 88 99 12 13 14
3x3 3x3

More Related Content

Similar to Arrays.pptx (20)

Arrays
ArraysArrays
Arrays
 
Unit 4
Unit 4Unit 4
Unit 4
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
Presentation of array
Presentation of arrayPresentation of array
Presentation of array
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
C
CC
C
 
Array
ArrayArray
Array
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptxdata structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
 
7array in c#
7array in c#7array in c#
7array in c#
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Array 2 hina
Array 2 hina Array 2 hina
Array 2 hina
 
Arrays
ArraysArrays
Arrays
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
2 Arrays & Strings.pptx
2 Arrays & Strings.pptx2 Arrays & Strings.pptx
2 Arrays & Strings.pptx
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 
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
 

Recently uploaded

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 

Recently uploaded (20)

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 

Arrays.pptx

  • 1. Arrays • An array is defined as the collection of similar type of data items stored at contiguous memory locations. • Arrays are the derived data type in C programming language which can store the primitive type of data such as int, char, double, float, etc.
  • 2. • C array is beneficial if you have to store similar elements. For example, if we want to store the marks of a student in 6 subjects, then we don't need to define different variables for the marks in the different subject. • Instead of that, we can define an array which can store the marks in each subject at the contiguous memory locations.
  • 3. Properties of Array • Each element of an array is of same data type and carries the same size, i.e., int = 4 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.
  • 4. 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.
  • 5. 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
  • 6. Declaration of C Array • data_type array_name[array_size]; • Example: • int marks[5];
  • 7. Initialization of C Array • marks[0]=80;//initialization of array • marks[1]=60; • marks[2]=70; • marks[3]=85; • marks[4]=75;
  • 8.
  • 9. Types of array • One dimensional array: A one dimensional array is a linear list consisting of related and similar data items (or) only one subscripted array is called as one or single dimensional arrays. • Declaration and initialization of one dimensional array: • Array initialization in compile time • int a[10]={10,20,30,40,50}; • one subscript
  • 10. • Two Dimensional Arrays: Storing or representing the data in two dimensional that is in tabular form (or) two subscripted array is called two dimensional array. • It is also known as a matrix. • Syntax: Data-type variable name [number of rows][number of columns]; • Example: int a [3][4]; • Initialization:- • int a[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};
  • 11. A 2D array’s elements are stored in continuous memory locations. It can be represented in memory using any of the following two ways: 1. Column-Major Order 2. Row-Major Order 1. Column-Major Order: In this method the elements are stored column wise, i.e. n elements of first column are stored in first n locations, n elements of second column are stored in next n locations and so on.
  • 12. • 2. Row-Major Order: In this method the elements are stored row wise, i.e. m elements of first row are stored in first m locations, m elements of second row are stored in next m locations and so on. • The array that we have in the example below is having the dimensions 5 and 4. • These dimensions are known as subscripts. So this array has first subscript value as 5 and second subscript value as 4. • So the array abc[5][4] can have 5*4 = 20 elements.
  • 13.
  • 14. Multidimensional arrays • A multi-dimensional array is an array that has more than one dimension. • It is an array of arrays; an array that has multiple levels. • The simplest multi-dimensional array is the 2D array, or two-dimensional array.
  • 15. • C allows arrays of three or more dimensions. • The general form of a multi-dimensional array is • Syntax: • data_type array_name[block_size][row_size][column_size]; • Example: int a[2][3][3]; •
  • 16. int a[2][3][3]; //array of type integer //number of blocks of 2D arrays:2 |rows:3 |columns:3 //number of elements:2*3*3=18 integer elements can be stored. block(1) 11 22 33 block(2) 12 13 14 44 55 66 21 31 41 77 88 99 12 13 14 3x3 3x3