Passing a Structure to a Function - C++ Function

C++ examples for Function:Function Parameter

Description

Passing a Structure to a Function

Demo Code

#include <iostream> 
  
using namespace std; 
  
struct SumParameters 
{ 
        int     valueA; 
        int     valueB; 
        int     result; 
}; //from  w w w .j  a v  a 2s . com
  
void ReturnSum(SumParameters& params) 
{ 
        params.result = params.valueA + params.valueB; 
} 
  
int main(int argc, char *argv [])
{ 
        SumParameters sum; 
        sum.valueA = 3; 
        sum.valueB = 6; 

        sum.result = 0; 
        ReturnSum(sum); 
        cout << sum.result << endl; 
  
        return 0; 
}

Result


Related Tutorials