The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
![]() |
Home ![]() ![]() |
||
![]() ![]() ![]() ![]() ![]() ![]() |
||
Structures as Return Types
{ double x = box.corner.x + box.width/2; double y = box.corner.y + box.height/2; Point result = {x, y}; return result; } To call this function, we have to pass a box as an argument (notice that it is being passed by reference), and assign the return value to a Point variable: Rectangle box = { {0.0, 0.0}, 100, 200 };Point center = findCenter (box); printPoint (center); The output of this program is (50, 100).
|
||
Home ![]() ![]() |