PASSING ARRAYS TO FUNCTIONS
Submitted by
VYSHAKH C B
19MSPHCP06
Msc.Computational Physics
ARRAY DEFINITION :
Array is a collection of variables belongings to the same data type. You can store
group of data of same data type in an array.
EXAMPLE FOR C ARRAYS:
● int a[10]; // integer array
● char b[10]; // character array i.e. string
TYPES OF C ARRAYS:
There are 2 types of C arrays. They are,
1. One dimensional array
2. Multi dimensional array
○ Two dimensional array
○ Three dimensional array
○ four dimensional array etc…
PASSING ARRAY TO FUNCTION :
Array can be passed to function by two ways :
a. Pass Array element by element
b. Pass Entire array
1 . PASS ARRAY ELEMENT BY ELEMENT
● Here individual elements are passed to function as argument.
● Duplicate carbon copy of Original variable is passed to
function .
● So any changes made inside function does not affects the
original value.
● Function doesn’t get complete access to the original array
element.
● Function passing method is “Pass by Value“
Passing a single array element to a function
Example 2. Passing a single array element to a function
1 . PASS ENTIRE ARRAY
● Here entire array can be passed as a argument to function .
● Function gets complete access to the original array .
● While passing entire array Address of first element is passed to function , any changes
made inside function , directly affects the Original value .
● Function Passing method : “Pass by Address“
● Parameter Passing Scheme : Pass by Reference
● Pass name of array as function parameter .
● Name contains the base address i.e ( Address of 0th element )
● Array values are updated in function .
● Values are reflected inside main function also
Passing a complete One-dimensional array to a function
Passing a Multi-dimensional array to a function
Example 2.Passing a Multi-dimensional array to a function
Thank you