Arrays

12

Click here to load reader

description

This is my first presentation that i have ever made.

Transcript of Arrays

Page 1: Arrays

ARRAYSBY:-

Mubashar Iqbal

Page 2: Arrays

OutlinesWhat an array is?TypesMemory allocationDeclaration and Definition Passing array to a functionDoes arrays resembles Pointers?Operation on arrays and it’s uses

Page 3: Arrays

An array is……..Derived data type

Collection of same data type under one common name.

It’s element can be of any type like int ,float,char and user defined datatypes like objects and structures.

Page 4: Arrays

TypesOne dimensional

A[0]

A[1]

A[2]

A[3]

A[4]

A[5]

A[0][0]

A[0][1]

A[0][2]

A[0][3]

A[0][4]

A[0][5]

A[1][0] A[1][2] A[1][3] A[1][4] A[1][5] A[1][6]

A[2][1] A[2][2] A[2][3] A[2][4] A[2][5] A[2][6]

• Two dimensional

Page 5: Arrays

Types(cont…..)Multi Dimensional Arrays

3D arrays and 4D arrays etc...

• Location of an element of array is called index of the array.

Page 6: Arrays

Memory AllocationIf the array is float arr [ 5 ];

memory representation would be as follows: 1000 1004 1008 1012 1016

A[0] A[1] A[2] A[3] A[4]Total size required=size of(type)*size of

array = 4 *

5 = 20bytes

Page 7: Arrays

Declaration and Definition 1 Dimensional Array1. Declaration int Array[4]; float Array[4]; char Array[4];2. Initialization int Array[4]={0,1,2,3}; float Array[4]={1.1,1.2,1.3,1.4}; char Array[4]={“Ali”};

Page 8: Arrays

Declaration and Definition2 Dimensional Array1.Declarationint A[2][2];char A[a][2];2.Intializationint A[2][2]={{1,2}, {3,4}};Note:-In c++ first element is always at zero

position.

Page 9: Arrays

Passing an array to a functionPassing an array to a function is same as passing a

variable by reference.Syntax void syntax(int [],int ){ body of function } main(){ Syntax(array,size); }

Page 10: Arrays

Resemblance of arrays with pointersAn array is like a pointer but not a pointer.It’s name gives us it’s address.Internally it behaves like a pointer because It

stores address. Each of it’s element has a different address.

Page 11: Arrays

Operations on it and usesElements of array can be sorted(arranged in

a definite manner), deleted (any element can be deleted)and traversed(desired element can be found).

Arrays are used to solve problems related to matrices and sets as well.

We can store large data easily e.g. record of 100 students etc.

Page 12: Arrays

Thanks……………….

QUESTIONS