Home > Back-end >  Small white sincerely ask c problem.
Small white sincerely ask c problem.

Time:11-14

Write a function Calc (float firstNum, float secondNum, pSum float * and * float pDiff) implementation as addition and subtraction of two Numbers, the first two parameters are used for computing the operands, with default parameter values, the latter two parameter is a pointer, save and with poor results, respectively,
Write a function Calc (float firstNum, float secondNum, float& The sum, float& Diff) implementation as addition and subtraction of two Numbers, the first two parameters are used for computing the operands, with default parameter values, the latter two parameters are reference variables, save and with poor results, respectively,

Two slightly different topic endless hope bosses can give a little help. Thanks

CodePudding user response:

The first function argument can be a reference or pointer to a variable, the second function of the argument may be either a variable or a pointer

CodePudding user response:

 
Bool Calc (float firstNum=0.0, float secondNum=0.0, float * pSum=null, float * pDiff=null) {
If (pSum==null | | pDiff==null) return false.
* pSum=firstNum + secondNum;
* pDiff=firstNum - secondNum;
return true;
};

Bool Calc (float firstNum=0.0, float secondNum=0.0, float & amp; PSum=0.0, float & amp; PDiff=0.0) {
PSum=firstNum + secondNum;
PDiff=firstNum - secondNum;
return true;
};

Call, so use:
 
Bool ret.
Floot first=10.1, second=5.3, the sum and diff.
Calc (first, second, & amp; The sum, & amp; The diff); The first function//
Calc (first, second, the sum and diff);//the second function

The return value of true said the call is successful, false say pointer is illegal,
After the success of the call, and values, the difference value stored in the sum and diff respectively,
  • Related