You can pass structures as parameters just like any built in data type. For example, printPoint below takes a point as an argument and outputs it in the standard format. If you call printPoint (blank), it will output (3, 4).
That version of the function uses pass by value to make a copy of the point that is passed in. For a very simple struct, we may be willing to pay the price of an unneeded copy. But in general, it is better to use pass by reference to pass structs to avoid that work. And, if the function will not modify the object, we should use pass by const reference. So we will prefer to write functions like this:
Similarly, we can return a struct from a function. To do so, we use the structβs type as the return type. Here is a function that takes a point and returns itβs mirror image over the y-axis:
Construct a function that takes in three Point structures and returns a new point where the x value is the the average of the three pointsβ x coordinates and the y value is the average of the three pointsβ y coordinates. Calculate the x average before the y average.