Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

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

Answer Attachments

Exams With Marking Schemes

Related Questions