Arrayppt
Arrayppt
Arrayppt
• An array is a group of consective memory locations with same name and data
type.
• Simple variable is a single memory location with unique name and a type.
But an Array is collection of different adjacent memory locations. All these
memory locations have one collective name and type.
• The memory locations in the array are known as elements of array. The total
number of elements in the array is called length.
• The elements of array is accessed with reference to its position in array, that
is call index or subscript.
Syntax for array declaration:
Index/subscript/
0 1 2 3 4
34 56 30 40 50
Advantages / Uses of Arrays
Arrays can store a large number of value with single name.
Arrays are used to process many value easily and quickly.
The values stored in an array can be sorted easily.
The search process can be applied on arrays easily.
Types of Arrays:
One-Dimensional Array
Two-Dimensional Array
Multi-Dimensional Array
One-D
Array
A type of array in which all elements are arranged in the form of a list is
known as 1-D array or single dimensional array or linear list.
•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 2120H. Then, the address of the mark[1] will be 2124H.
Similarly, the address of mark[2] will be 2128H and so on
Eg: Sample Program to input marks of 5 students and print it.
#include <stdio.h>
int main()
{ int i, n;
int marks[50];
printf("enter the size of the array");
scanf("%d", &n);
Syntax:
data_type identifier[length]={ List of values };
o Data _type: Data type of values to be stored in the array.
o Identifier: Name of the array.
o Length: Number of elements
o List of values: Values to initialize the array. Initializing values must be
constant
One-D array Initialization Example
#include <stdio.h>
int main () {
int main() {
int values[5];
12 25 33 37 48
o Ascending Order
o Descending Order
48 37 33 25 12
Techniques Of Sorting Array
There are various techniques of sorting array:
o Selection Sort
o Bubble Sort
o Insertion Sort
o Merge Sort
o Quick Sort
Selection Sort
Selection sort is a technique that sort an array. It selects an element in the
array and moves it to its proper position. Selection sort works as
follows: