At Westonci.ca, we connect you with the answers you need, thanks to our active and informed community. Ask your questions and receive accurate answers from professionals with extensive experience in various fields on our platform. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.
Sagot :
Answer:
Following are the code to this question:
#include <iostream>//header file
using namespace std;
int triplebyValue(int count)//defining a method triplebyValue
{
int x=count*3;//defining a variable x that multiply by 3 in the count
return x;//return value of x
}
void triplebyReference(int& count)//defining a method triplebyReference that hold count variable as a reference in parameter
{
count*=3;//multipling a value 3 in the count variable
}
int main()//main method
{
int count;//defining integer variable
count=triplebyValue(3);//use count to call triplebyValue method
cout<<"After call by value, count= "<<count<<endl;//print count value with message
triplebyReference(count);//calling a method triplebyReference
cout<<"After call by reference, count= "<<count<<endl;//print count value with message
return 0;
}
Output:
After call by value, count= 9
After call by reference, count= 27
Explanation:
In this code two methods "triplebyValue and triplebyReference" are declared, which accepts a count variable as a parameter, and in both multiply the count value by 3 and return its value.
Inside the main method, an integer variable "count" is declared that first calls the "triplebyValue" method and holds its value into count variable and in the next, the method value is a pass in another method that is "triplebyReference", and use print method to print both methods value with a message.
Thanks for using our service. We aim to provide the most accurate answers for all your queries. Visit us again for more insights. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Your questions are important to us at Westonci.ca. Visit again for expert answers and reliable information.