Help with C++ code: #include <iostream> using namespace std; void fun(int, int,
ID: 3862260 • Letter: H
Question
Help with C++ code:
#include <iostream>
using namespace std;
void fun(int, int, int);
int main()
{
int a = 1, b = 2, c = 3;
cout << "The values of a, b, and c ";
cout << "are: " << a << " " << b << " " << c << endl;
fun(a, b, c);
return 0;
}
void fun(int c, int b, int a)
{
cout << "The values of a, b, and c within the function ";
cout << "are: " << a << " " << b << " " << c << endl;
}
Based on the result, what is the rule for determining which actual parameters are associated with which formal parameters?
CAWINDOWSVsystem32cmd.exe The values of a, b, and c are: 1 2 3 The values of a, b, and c within the function are: 3 2 1 Press any key to continueExplanation / Answer
void fun(int, int, int);
This line means that there is a function named fun which will takes three integer values as input. At this point of time you haven't decided the name to be given to the values.
void fun(int c, int b, int a){
......
}
Here you define the function and say that the !st parameter passed during function call will be c. Similarly second one is B and third is a.
Now when you call, fun(a, b, c); The value of a--> 1 goes to the first formal parameter c. and the second valuie b=2 goes to formal parameter b and the third value c--> 3 goes to formal parameter a.
HENCE THE WAY OF DETERMINIING WHICH ACTUAL PAARMETER BECOMES WHICH FORMAL PARAMETER IS TO SEE THE ORDER OF PARAMETERS IN THE FUNCTION DEFINATION AND TO SEE THE ORDER OF PARAMETERS IN FUNCTION CALL.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.