| Structures |
| |
| Passing structure to function |
| |
| There are three methods by which the values of structure can be transferred from one function to another: |
| |
| 1. The first method is to pass each member of the structure as an actual argument of the function call. |
| |
| The actual argument is then treated independently like ordinary variables. |
| |
| 2. The second methods involve passing of a copy of the entire structure to the called function |
| |
| Since the function is working on a copy of the entire structure to the called function, changes are not reflected in the original structure (in the calling function). |
| |
| It is necessary for the entire function to return the entire structure back to the calling function. |
| |
| 3. The third approach employs a concept called pointers to pass the structure as an argument . |
| |
| In this case, the address location of the structure is passed to the called function. |
| |
| The function can access indirectly the entire structure and work on it. |
| |
| The general format of sending a copy of structure to the called function is: |
| |
| function_name (structure_variable_name) |
| |
| |
| |
| |
| |