Showing posts with label Return Arrays from to Function. Show all posts
Showing posts with label Return Arrays from to Function. Show all posts

Tuesday, 25 October 2016

Passing Arrays to Function in C Programming

Passing Arrays to Function 

To pass a single-dimension array as an argument in a function, you would have to declare a formal parameter in one of following three ways. 
 1st method  Formal parameters as a pointer
2nd method  Formal parameters as a sized array
3rd method Formal parameters as an unsized array
Example :- 

Return Arrays from to Function 

C programming does not allow to return an entire array as an argument to a function.However, you can return a pointer to an array by specifying the array's name without an index.


 Example :-
 
Pointer to a Array 
An array name is a constant pointer to the first element of the array.

 balance is a pointer to &balance[0], which is the address of the first element of the array balance. Thus, the following program fragment assigns p as the address of the first element of balance
Example :- Once you store the address of the first element in ‘p’, you can access the array elements using *p, *(p+1), *(p+2), and so on.