Professional Documents
Culture Documents
5 6314563731506332403
5 6314563731506332403
Array
Array
Collection of similar type of data items
Stored at contiguous memory locations
Size of an array
Array
Using elements of an array
Just as simple variables
array[3]=25;
array[3]=array[2]+100;
array[3]=array[0]+array[1];
printf(“%d”,array[3]);
scanf(“%d”,&array[3]);
array[3]=array+25;
array=array*3;
Array
Initializing array
dataType arrayName[arraySize]={, ,…, };
Array
Initializing array
dataType arrayName[arraySize]={, ,…, };
Array
Initializing array
dataType arrayName[arraySize]={, ,…, };
Array
Array
Using elements of an array
Array
Using elements of an array
Array
Functions with arrays
return_type function_name(data_type array_name[]) Formal parameter
{
………
}
function_name(array_name); Actual parameter
Array
Functions with arrays
Array
Functions with arrays: Using the size of array
return_type function_name(data_type array_name[],int size_of_array) Formal parameter
{
………
}
function_name(array_name,size); Actual parameter
Array
Functions with arrays
Array
Functions with elements of array
Array
Function parameter(s) with elements of array: Call by value
Function parameter(s) with full array: Call by reference
Array
Function parameter(s) with full array: Call by reference
Base address
101
a[0] a[1] a[2] a[3] a[4]
10 20 30 20 10
5
101-102 103-104 105-106 107-108 109-110 return address
Array
Function parameter(s) with full array: Call by reference
Calculating address of other elements using base address
address of element [i]=base address+(i*scale factor of data type) a[0] a[1] a[2] a[3] a[4]
address of a[3]=101+(3*2) 10 20 30 20 10
address of a[3]=107 101-102 103-104 105-106 107-108 109-110
Array
2D Array
dataType arrayName[rowSize][columnSize];
int a[2][3];