Structures become really useful when functions can work on whole records: a function to print a student, another to compute a salary. This section shows how a structure travels into a function and back out.
Passing a structure by value
A structure is passed like any other variable: by value. The function receives a complete copy of the structure, so changes made inside the function do not affect the caller’s variable. (This differs from an array, which is passed as an address.)
For the function to know the type, the structure must be declared before the functions that use it, normally at the top of the file, outside all functions.
Returning a structure
A function can return a whole structure. Its return type is the structure type, and the result is assigned to a variable of the same type. This is one way for a function to give back several values at once.
Constant structure arguments
Since C99, a structure value can be written directly in a call with a compound literal: (struct tag){ values }.
Passing a pointer avoids copying and lets the function modify the original; members are then accessed with the arrow operator ->, covered with pointers in Unit 7.
Key takeaways
Structures are passed by value: the function works on a copy.
A function can return a structure, which is assigned to a variable of the same type.
Declare the structure type at file level, before the prototypes.
Compound literals (C99) create structure values directly in a call.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Rewrite deposit from question 2 so that the caller’s balance really increases, without using pointers, and show the call.
Show worked answer
Make the function return the updated structure: struct acc deposit(struct acc a) { a.balance = a.balance + 500; return a; }. The call becomes mine = deposit(mine);. The function still works on a copy, but the modified copy is returned and assigned back to mine, so mine.balance becomes 1500.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/structures-and-unions/structures-as-function-arguments/ to read this page.