Pass structure using a structure reference : structure parameter « Structure « C++ Tutorial






#include <iostream>
using namespace std;

struct ResultStructure
{
  float base;
  float height;
  float area;
};

void f(struct ResultStructure &area);

int main () 
{
       ResultStructure myResultStructure;


    myResultStructure.base = 12;
    myResultStructure.height = 23;
    f(myResultStructure);

    cout << "The area is " << myResultStructure.area << " \n";
   return 0;
}


void f(ResultStructure &area)
{
   area.area = .5f * (area.base * area.height);
}
The area is 138








8.3.structure parameter
8.3.1.Pass structure to a function
8.3.2.Pass structure using a structure reference
8.3.3.Pass structure to a function as a pointer
8.3.4.structure variables as array elements