We will explain the concept of arrays using an analogy. Take a situation in which we have 20 students in a class and we have been asked to write a program that reads and prints the marks of all these 20 students.
Unit II : Arrays
and Strings
CHAPTER
5 : ARRAYS
Takeaways
•
Array declaration
•
Linear and binary search
•
Operations on 2D arrays
•
Application of arrays
•
Array length
•
Passing arrays to functions
•
Multidimensional arrays
•
Operations on arrays
•
Two-dimensional arrays
•
Array implementation of sparse matrices
INTRODUCTION TO ARRAYS
We
will explain the concept of arrays using an analogy. Take a situation in which
we have 20 students in a class and we have been asked to write a program that
reads and prints the marks of all these 20 students. In this program, we will
need 20 integer variables with different names, as shown in Figure 5.1.

Now
to read values for these 20 different variables, we must have 20 read
statements. Similarly, to print the value of these variables, we need 20 write
statements.If it is just a matter of 20 variables, then it might be acceptable
for the user to follow this approach. But would it be possible to follow this
approach if we have to read and print marks of the students
•
in the entire course (say 100 students)
•
in the entire college (say 500 students)
•
in the entire university (say 10000 students)
The
answer is no, definitely not! To process large amount of data, we need a data
structure known as array. An array is
a collection of similar data elements. These data elements have the same data
type. The elements of the array are stored in consecutive memory locations and
are referenced by an index (also known as the subscript).
Programming Tip:
In
an array of size n, the index ranges from 0 to n−1.
Subscript
is an ordinal number which is used to identify an element of the array. Some
examples where the concept of an array can be used include:
•
List of temperatures recorded on every day of the month
•
List of employees in a company
•
List of students in a class
•
List of products sold
•
List of customers
Programming in C: Unit II (a): Arrays : Tag: : - Introduction to Arrays in C Programming
Programming in C
CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation
Professional English II
HS3251 2nd Semester 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation
Statistics and Numerical Methods
MA3251 2nd Semester 2021 Regulation M2 Engineering Mathematics 2 | 2nd Semester Common to all Dept 2021 Regulation
Engineering Graphics
GE3251 eg 2nd semester | 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation
Physics for Electrical Engineering
PH3202 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation
Basic Civil and Mechanical Engineering
BE3255 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation
Electric Circuit Analysis
EE3251 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation
Physics for Electronics Engineering
PH3254 - Physics II - 2nd Semester - ECE Department - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation
Electrical and Instrumentation Engineering
BE3254 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation
Circuit Analysis
EC3251 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation
Materials Science
PH3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation
Basic Electrical and Electronics Engineering
BE3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation
Physics for Civil Engineering
PH3201 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation
Basic Electrical, Electronics and Instrumentation Engineering
BE3252 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation
Physics for Information Science
PH3256 2nd Semester CSE Dept | 2021 Regulation | 2nd Semester CSE Dept 2021 Regulation
Basic Electrical and Electronics Engineering
BE3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation
Programming in C
CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation