ADS

Functions and Array in C Programming | C Programming

Functions and Array in C Programming


We can pass an entire array of values into a function just as we pass individual variables. In this task it is essential to list the name of the array along with functions arguments without any subscripts and the size of the array as arguments     
For example:   
Largest(a,n);   
will pass all the elements contained in the array a of size n. the called function expecting this call must  be appropriately defined. The largest function header might look like:     
float smallest(array,size);   
float array[];   
int size; 

The function smallest is defined to take two arguments, the name of the array and the size of the array  to specify the number of elements in the array. The declaration of the formal argument array is made as  follows:
     
float array[ ];
    
The above declaration indicates to compiler that the arguments array is an array of numbers. It is not  necessary to declare size of the array here. While dealing with array arguments we should remember  one major distinction. If a function changes the value, the value of an array elements then these changes will be made to the original array that passed to the function. When the entire array is passed as an argument, the contents of the array are not copied into the formal parameter array instead information about the address of the array elements are passed on to the function. Therefore, any changes introduced to array elements are truly reflected in the original array in the calling function.

Post a Comment

0 Comments