C++ Array

declare arrays:

arraytype arrayName[arraySize]; //basic syntax

example:

int zakiLive[10];

Initialize arrays:

int zakiLive[5]={4,5,6,8};

zakiLive[3]=8
It means value 8 is in 3rd index in array zakiLive as index in array count from 0 and it goes on..
Here is an example of array

C++ Arrays have some types:

Multi-Dimensional Arrays:

 

syntax can be like this

array_data_type  array_name[size1][size2][size3]……..[sizeN];

Two Dimensional Arrays(It is one kind of multidimensional arrays):

type arrayName[x][y];

Initialize Two Dimensional Arrays:

int a[3][4]={
{0,1,2,3},
{4,5,6,7},
{8,9,10,11}
};

We can also write equivalent like this

int a[3][4]={0,1,2,3,4,5,6,7,8,9,10,11};

We can accesss Two-Dimensional Array elemets by

int valueArray=a[2][3];

Here is a code

C++ Pointer to an Array

Here it is happeing like this shown above.

There are another 2 types of C++ array functioning with pointer

Passing Arrays to Function and Returning Array From Functions

Now let discuss in details

Passing Arrays to Function:

What we know from the function  synatx is

But it’s not possible to pass a full array to the argument by using an index number..But we can pass an array by using without an index..This process can be done by three steps

Way-1
Formal Parameters as a pointer

Way-2
Formal Parameters as a size array as follows

Way-3
Formal Paramaeters as an unsized array as follows

The example given here with array without size

 

Return Array from Functions:

We will discss this later more In Sha Allah 🙂