C Unit 4
C Unit 4
Arrays – Declaration and Definition of Array, accessing elements in array, Storing values in
array, linear search, binary search, bubble sort, Two – dimensional arrays, multidimensional
arrays. Arrays and Pointers, Pointer Arithmetic and arrays, array of pointers, Passing array
to function.
These are used to store multiple values in a single variable, instead of declaring separate variables
for each value.
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.
The array is the simplest data structure where each data element can be randomly accessed by
using its index number.
The lowest address corresponds to the first element and the highest address to the last element.
Why do we need arrays?
We can use normal variables (v1, v2, v3, ..) when we have a small number of objects, but if
we want to store a large number of instances, it becomes difficult to manage them with normal
variables. The idea of an array is to represent many instances in one variable.
Declaring Arrays:
The arraySize must be an integer constant greater than zero and type can be any valid C data
type.
Example:
int marks[5];
Or
float mark[5];
Initialization of C Array:
The simplest way to initialize an array is by using the index of each element.
The 2D array is organized as matrices which can be represented as the collection of rows and
columns.
Example:
• Initializing Two-Dimensional Arrays: