C++ Function Parameter Passing a Structure to a Function

Description

C++ Function Parameter Passing a Structure to a Function

#include <iostream> 
  
using namespace std; 
  
struct SumParameters 
{ 
        int     valueA; 
        int     valueB; 
        int     result; 
}; /*from   ww  w . j a v  a 2s.  c  o  m*/
  
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; 
}



PreviousNext

Related