SlideShare a Scribd company logo
CH.5 ARRAYS IN C
-By Prof. Sangeeta Borde
� Program to take 5 values from the user and store
them in an array .Print the elements stored in the
array
� Program to find the average of n numbers using
arrays.
� Program to store n numbers in array and display
them in reverse order.
� Program to store n numbers in array and didplay
maximum of them.
EXAMPLES:
TYPES OF ARRAY
ONE DIMENSIONAL TWO DIMENSIONAL MULTIDIMENSIONAL
1. A One dimensional array has one subscript. One
dimensional array(1D) is an array which is
represented either in one row or in one column.
2. The one dimensional arrays are known as
vectors.
3. It is also known as single dimensional array.
1.ONE DIMENSIONAL ARRAY
Row
1 D
Array
1.ONE DIMENSIONAL ARRAY
continue…
Column
1.Declaration of 1 dimensional array.
2.Initialization of one dimensional array.
3.Accessing one dimensional array
1. An array consists of two subscripts is known as
array of the array.
2. In two dimensional array is divided into rows and
column. These are often known as array of the
array.
2.Two Dimensional Array
� Syntax:
� Datatype array_name[row_size] [column_size]
� Ex:int matrix[3][4];
Declaration of 2D array
� For example:-
int a[2][3]={0,0,0,1,1,1,1};
Initializes the elements of the first row to zero and
the second row to one.
The initialization is done row by row.
The above statement can also be written as:
Int a[2][3]={{0,0,0},{1,1,1}};
Initialization of two Dimensional
Array
� Q 1.program to store numbers in matrix and
display matrix.
Example for accessing two
dimensional array elements:
� 1.Row Major Representation-
� In this method the elements are stored row wise.
� i.e n elements of first row are stored in first n
locations, n elements of second row are stored in
next n locations and so on.
� i.e row1,row2,row3
Memory Representation of two dimensional
Array(Row Major and Column Major)
Mark
s[0][
0]
Mark
s[0[[
1]
Mark
s[0][
2]
Mark
s[1][
0]
Mark
s
[1][1]
Mark
s[1][
2]
Mark
s
[2][0]
Mark
s[2][
1]
Mark
s[2][
2]
1 2 3 4 5 6 7 8 9
1000 1002 1004 1006 1008 1008 1010 1012 1014
1.Row Major Representation-
Element
Value
Address
Mark
s[0][
0]
Mark
s[1][
0]
Mark
s[2][
0]
Mark
s[0][
1]
Mark
s[1][
1]
Mark
s[2][
1]
Mark
s[0][
2]
Mark
s[1][
2]
Mark
s[2][
2]
1 4 7 2 5 8 3 6 9
1000 1002 1004 1006 1008 1010 1012 1014 1016
2.Column Major Representation
Element
Value
Address
� Let A[m,n] is the two dimension array,To find address
of A[I,j] in row major order consider formula—
� Loc A[i][j]=BaseAddress(A)+w(N*i+j)
Where,
M-No. of rows,
N-No of columns
Base Address(A)=Starting address of the array.
i.e address of [0][0] element.
W=size of the data type used i.e no of bytes per storage
location for one element of the array.
Address Calculation of 2D of array
elements: Row Major Order
� Let A[m,n] is the two dimension array,To find address
of A[I,j] in row major order consider formula—
� Loc A[i][j]=BaseAddress(A)+w(M*j+i)
Where,
M-No. of rows,
N-No of columns
Base Address(A)=Starting address of the array.
i.e address of [0][0] element.
W=size of the data type used i.e no of bytes per storage
location for one element of the array.
Address Calculation of 2D of array
elements: Row Major Order
� In Row Major & Column Major
1. For the array marks[3][3] calculate the address of
marks[1][2] in row major and column major order.
Example:
� Arrays can have more than one dimension, these
arrays-of arrays are called multidimensional
arrays.
� Syntax:
Data_type name[size1][size2][size3]…[size4]
Example:
Three dimensional integer array:
Int threedim[2][5][3];
Multi-dimensional array
� Arrays are used in wide range of applications:
1.Arrays are used to store List of values.
2.Arrays are used to maintain multiple variables with
the same name.
3.Arrays are used to perform matrix operations.
4.Arrays are used to implement mathematical
vectors and matrices, as well as other kinds of
rectangular tables.
5.Arrays are used to implement search Algo’s
Array Applications:
� Arrays are used to implement sorting Algorithms:
� Insertion Sort, Selection Sort,Bubble Sort,Quick
sort,Merge sort etc.
� Arrays are used to implement Data Structures.
▪ Stack using arrays
▪ Queue using arrays
▪ Arrays are also used to implement CPU
scheduling Algorithms.
Array Applications: continue…
1. It is better and convenient way of storing the
data of same data type with same size.
2. It allows us to store known number of elements
in it.
3. Arrays allocate memory in contiguous memory
locations for all its elements. Hence there is no
chance of extra memory being allocated in case
of arrays.
4. This avoids memory overflow or shortage of
memory in arrays.
Advantages of an Arrays:
� In arrays, the elements can be accessed randomly
by using the index number. Iterating the arrays
using their index is faster compared to any other
methods like linked list etc.
� It allows to store the elements in any dimensional
array
Advantages of an Arrays:
continue…
1. Inserting and deleting the records from the array
would be costly since we add/delete the
elements from the array, We need to manage
space too.
2. Allocating more memory than the requirement
leads to wastage of memory space and less
allocation of memory also leads to a problem.
Disadvantages of Array:
� In C programming, there are two methods to pass
the array to the function namely, passing array
elements by elements and passing entire array to
function.
Passing Arrays to function.
� Passing array elements to a function is similar to
passing variables to a function.
� In this method, array elements are passed one by
one to function.
� The function gets access only one element at a
time and cannot modify this value.
Passing Arrays to function.
� Example:
Void display(int age1,int age2)
{
Printf(“%dn”,age1);
Printf(“%dn”,age2);
}
main()
{
int ageArray[]={20,40,60,12};
display(ageArray[1],ageArray[2]);
}
Passing Arrays to function
� To send entire array to the function ,we will only
send in the name of the array as argument, which
is nothing but the address of the starting element
of the array, or we can say the starting memory
address.
� Base address of the array is the address of the
very first element of the array.
� i.e address of the 0th element in linear array.
� So the array name marks is equivalent to
&marks[0].
� It is a constant pointer cannot be changed.
Passing entire array to function
THANK YOU

More Related Content

DOCX
PPTX
Various Operations Of Array(Data Structure Algorithm).pptx
PPTX
PPTX
Array 2 hina
PPTX
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
PDF
Arrays
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
PPTX
Various Operations Of Array(Data Structure Algorithm).pptx
Array 2 hina
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
Arrays
Unit4pptx__2024_11_ 11_10_16_09.pptx

Similar to UNIT-5_Array in c_part1.pptx (20)

PPTX
Array
PPTX
arrays.pptx
PDF
Unit 2
DOC
Ocs752 unit 2
PDF
Chapter 4 (Part I) - Array and Strings.pdf
PPTX
data structure unit -1_170434dd7400.pptx
PDF
array-191103180006.pdf
PPT
Chapter 3 ds
PPTX
Array Introduction One-dimensional array Multidimensional array
PPT
Arrays and vectors in Data Structure.ppt
PDF
Introduction to Arrays in C
PPTX
Arrays accessing using for loops
PDF
M v bramhananda reddy dsa complete notes
PDF
12000121037.pdf
PDF
Arrays and library functions
PPT
PPTX
Arrays 1D and 2D , and multi dimensional
PDF
Cunit3.pdf
PPTX
PPt. on An _Array in C
Array
arrays.pptx
Unit 2
Ocs752 unit 2
Chapter 4 (Part I) - Array and Strings.pdf
data structure unit -1_170434dd7400.pptx
array-191103180006.pdf
Chapter 3 ds
Array Introduction One-dimensional array Multidimensional array
Arrays and vectors in Data Structure.ppt
Introduction to Arrays in C
Arrays accessing using for loops
M v bramhananda reddy dsa complete notes
12000121037.pdf
Arrays and library functions
Arrays 1D and 2D , and multi dimensional
Cunit3.pdf
PPt. on An _Array in C
Ad

More from sangeeta borde (11)

PPTX
CH 4_TYBSC(CS)_Data Science_Visualisation
PDF
Ch.3 Data Science Data Preprocessing.pdf
PDF
Data Science_Chapter -2_Statical Data Analysis.pdf
PPTX
Ch1_Introduction to DATA SCIENCE_TYBSC(CS)_2024.pptx
PDF
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
PPTX
CH2_CYBER_SECURITY_FYMSC(DS)-MSC(CS)-MSC(IMCA).pptx
PPTX
FYBSC(CS)_UNIT-1_Pointers in C.pptx
PPTX
CH.4FUNCTIONS IN C (1).pptx
PDF
3. Test Scenarios & Test Cases with Excel Sheet Format (1).pdf
PPTX
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
PPTX
2024-25 TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
CH 4_TYBSC(CS)_Data Science_Visualisation
Ch.3 Data Science Data Preprocessing.pdf
Data Science_Chapter -2_Statical Data Analysis.pdf
Ch1_Introduction to DATA SCIENCE_TYBSC(CS)_2024.pptx
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
CH2_CYBER_SECURITY_FYMSC(DS)-MSC(CS)-MSC(IMCA).pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptx
CH.4FUNCTIONS IN C (1).pptx
3. Test Scenarios & Test Cases with Excel Sheet Format (1).pdf
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2024-25 TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
Ad

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Computing-Curriculum for Schools in Ghana
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Classroom Observation Tools for Teachers
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
master seminar digital applications in india
PPTX
Cell Structure & Organelles in detailed.
Supply Chain Operations Speaking Notes -ICLT Program
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Weekly quiz Compilation Jan -July 25.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
2.FourierTransform-ShortQuestionswithAnswers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
Computing-Curriculum for Schools in Ghana
O7-L3 Supply Chain Operations - ICLT Program
VCE English Exam - Section C Student Revision Booklet
Classroom Observation Tools for Teachers
O5-L3 Freight Transport Ops (International) V1.pdf
Cell Types and Its function , kingdom of life
master seminar digital applications in india
Cell Structure & Organelles in detailed.

UNIT-5_Array in c_part1.pptx

  • 1. CH.5 ARRAYS IN C -By Prof. Sangeeta Borde
  • 2. � Program to take 5 values from the user and store them in an array .Print the elements stored in the array � Program to find the average of n numbers using arrays. � Program to store n numbers in array and display them in reverse order. � Program to store n numbers in array and didplay maximum of them. EXAMPLES:
  • 3. TYPES OF ARRAY ONE DIMENSIONAL TWO DIMENSIONAL MULTIDIMENSIONAL
  • 4. 1. A One dimensional array has one subscript. One dimensional array(1D) is an array which is represented either in one row or in one column. 2. The one dimensional arrays are known as vectors. 3. It is also known as single dimensional array. 1.ONE DIMENSIONAL ARRAY Row 1 D Array
  • 5. 1.ONE DIMENSIONAL ARRAY continue… Column 1.Declaration of 1 dimensional array. 2.Initialization of one dimensional array. 3.Accessing one dimensional array
  • 6. 1. An array consists of two subscripts is known as array of the array. 2. In two dimensional array is divided into rows and column. These are often known as array of the array. 2.Two Dimensional Array
  • 7. � Syntax: � Datatype array_name[row_size] [column_size] � Ex:int matrix[3][4]; Declaration of 2D array
  • 8. � For example:- int a[2][3]={0,0,0,1,1,1,1}; Initializes the elements of the first row to zero and the second row to one. The initialization is done row by row. The above statement can also be written as: Int a[2][3]={{0,0,0},{1,1,1}}; Initialization of two Dimensional Array
  • 9. � Q 1.program to store numbers in matrix and display matrix. Example for accessing two dimensional array elements:
  • 10. � 1.Row Major Representation- � In this method the elements are stored row wise. � i.e n elements of first row are stored in first n locations, n elements of second row are stored in next n locations and so on. � i.e row1,row2,row3 Memory Representation of two dimensional Array(Row Major and Column Major)
  • 11. Mark s[0][ 0] Mark s[0[[ 1] Mark s[0][ 2] Mark s[1][ 0] Mark s [1][1] Mark s[1][ 2] Mark s [2][0] Mark s[2][ 1] Mark s[2][ 2] 1 2 3 4 5 6 7 8 9 1000 1002 1004 1006 1008 1008 1010 1012 1014 1.Row Major Representation- Element Value Address
  • 12. Mark s[0][ 0] Mark s[1][ 0] Mark s[2][ 0] Mark s[0][ 1] Mark s[1][ 1] Mark s[2][ 1] Mark s[0][ 2] Mark s[1][ 2] Mark s[2][ 2] 1 4 7 2 5 8 3 6 9 1000 1002 1004 1006 1008 1010 1012 1014 1016 2.Column Major Representation Element Value Address
  • 13. � Let A[m,n] is the two dimension array,To find address of A[I,j] in row major order consider formula— � Loc A[i][j]=BaseAddress(A)+w(N*i+j) Where, M-No. of rows, N-No of columns Base Address(A)=Starting address of the array. i.e address of [0][0] element. W=size of the data type used i.e no of bytes per storage location for one element of the array. Address Calculation of 2D of array elements: Row Major Order
  • 14. � Let A[m,n] is the two dimension array,To find address of A[I,j] in row major order consider formula— � Loc A[i][j]=BaseAddress(A)+w(M*j+i) Where, M-No. of rows, N-No of columns Base Address(A)=Starting address of the array. i.e address of [0][0] element. W=size of the data type used i.e no of bytes per storage location for one element of the array. Address Calculation of 2D of array elements: Row Major Order
  • 15. � In Row Major & Column Major 1. For the array marks[3][3] calculate the address of marks[1][2] in row major and column major order. Example:
  • 16. � Arrays can have more than one dimension, these arrays-of arrays are called multidimensional arrays. � Syntax: Data_type name[size1][size2][size3]…[size4] Example: Three dimensional integer array: Int threedim[2][5][3]; Multi-dimensional array
  • 17. � Arrays are used in wide range of applications: 1.Arrays are used to store List of values. 2.Arrays are used to maintain multiple variables with the same name. 3.Arrays are used to perform matrix operations. 4.Arrays are used to implement mathematical vectors and matrices, as well as other kinds of rectangular tables. 5.Arrays are used to implement search Algo’s Array Applications:
  • 18. � Arrays are used to implement sorting Algorithms: � Insertion Sort, Selection Sort,Bubble Sort,Quick sort,Merge sort etc. � Arrays are used to implement Data Structures. ▪ Stack using arrays ▪ Queue using arrays ▪ Arrays are also used to implement CPU scheduling Algorithms. Array Applications: continue…
  • 19. 1. It is better and convenient way of storing the data of same data type with same size. 2. It allows us to store known number of elements in it. 3. Arrays allocate memory in contiguous memory locations for all its elements. Hence there is no chance of extra memory being allocated in case of arrays. 4. This avoids memory overflow or shortage of memory in arrays. Advantages of an Arrays:
  • 20. � In arrays, the elements can be accessed randomly by using the index number. Iterating the arrays using their index is faster compared to any other methods like linked list etc. � It allows to store the elements in any dimensional array Advantages of an Arrays: continue…
  • 21. 1. Inserting and deleting the records from the array would be costly since we add/delete the elements from the array, We need to manage space too. 2. Allocating more memory than the requirement leads to wastage of memory space and less allocation of memory also leads to a problem. Disadvantages of Array:
  • 22. � In C programming, there are two methods to pass the array to the function namely, passing array elements by elements and passing entire array to function. Passing Arrays to function.
  • 23. � Passing array elements to a function is similar to passing variables to a function. � In this method, array elements are passed one by one to function. � The function gets access only one element at a time and cannot modify this value. Passing Arrays to function.
  • 24. � Example: Void display(int age1,int age2) { Printf(“%dn”,age1); Printf(“%dn”,age2); } main() { int ageArray[]={20,40,60,12}; display(ageArray[1],ageArray[2]); } Passing Arrays to function
  • 25. � To send entire array to the function ,we will only send in the name of the array as argument, which is nothing but the address of the starting element of the array, or we can say the starting memory address. � Base address of the array is the address of the very first element of the array. � i.e address of the 0th element in linear array. � So the array name marks is equivalent to &marks[0]. � It is a constant pointer cannot be changed. Passing entire array to function