Write a C++ function called neg() that reverses the sign of its integer parameter.Write the function two ways-first by using a pointer parameter and then...

      

Write a C++ function called neg() that reverses the sign of its integer parameter.Write the function two ways-first by using a pointer parameter and then by using a reference parameter.Include a short program to demonstrate their operation.

  

Answers


Davis
#include
using namespace std;
void rneg(int &i); // reference version
void pneg(int *i); //pointer version
int main()
{
int i = 10;
int j = 20;
rneg(i);
pneg(&j);
cout <return 0
}
// using a reference parameter
void rneg(int &i)
{
i = -i;
}
// using a pointer parameter
void pneg( *i)
{
*i = - *i;
}
Githiari answered the question on May 31, 2018 at 17:05


Next: Explain the benefits of an appraisal system.
Previous: What is wrong with following program? // This program has an error. #include using namespace std; void triple(double &num); int main() { double d = 7.0; tripe(&d); cout << d; return 0; } //...

View More Computer Studies Questions and Answers | Return to Questions Index


Exams With Marking Schemes

Related Questions