Array

7
C++ Array C++ Array cpplab.pbworks.com

Transcript of Array

Page 1: Array

C++ Array C++ Array

cpplab.pbworks.com

Page 2: Array

www.company.com

ArraysDefinition:

An array is a series of elements of the same type.

Why using array?

To store different of the same type with unique identifier.

For example, we can store 5 values of the type int in an array without having to declare 5 different variables.

cpplab.pbworks.com

Page 3: Array

www.company.com

How the array represented?For example, an array to contain 6 integer values of type int called name could be represented like this:

Declaration format:Data-type name [ size ];

For example,int x[4];

Array Representation

cpplab.pbworks.com

Page 4: Array

www.company.com

Assigning values to array:-Using { }: int x[3]={3,4,7};

Note: the elements between the braces {} must not be larger than the size.

Assigning value to each variable uniquely: int a[2];

a[0]=10;

a[1]=13;

Array Assignment

cpplab.pbworks.com

Page 5: Array

www.company.com

Continous ..

Insert value by cin : Insert value for each element :

cin>>s[5]; using for loop: int s[10];for (int i=0;i<10;i++)cin>>s[i];

Ori<=9

cpplab.pbworks.com

Page 6: Array

www.company.com

Array Accessing

The format accessing the values of an array:

Name[index]

Example, a[6]

Sending an array to a function:

Type name (type [],type); prototype

Example, int addition (int a[],int size);

function-name (array-name , size); calling

Example, addition (a,7);

cpplab.pbworks.com

Page 7: Array

www.company.com

If you have any question please ask ..

You can send email to

[email protected]

You can wrtie a comment if you want any thing ..

^_^

cpplab.pbworks.com