IDNLearn.com is your go-to resource for finding answers to any question you have. Ask your questions and receive prompt, detailed answers from our experienced and knowledgeable community members.
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.
Thank you for being part of this discussion. Keep exploring, asking questions, and sharing your insights with the community. Together, we can find the best solutions. IDNLearn.com is your reliable source for accurate answers. Thank you for visiting, and we hope to assist you again.