Hello, I am trying to get some confirmation about how to pass to functions. If you want to assign default values to certain parameters, and have others defined inside the body of int main(), then the parameters which will have default values go at the end of the list. Is that correct?
i.e. The following code is wrong, because we cannot leave a black in the function call on the third line of the main function. However, if we switch the prototype to void Passing (int a, int c, int b = 1); and the function definition to void Passing (int a , int c, int b) everything will be okay and we can call the function as Passing (a, c).
In brief, we cannot do this EVER:
Passing( a, , c)right?
#include <iostream>
using namespace std;
void Passing (int a , int b = 1 , int c);
int main()
{
int a = 0;
int c = 0;
Passing ( a, , c);
}
void Passing(int a, int b, int c)
{
cout << a << b << c << endl;
}
And I dont understand how Passing(3) is equivalent to Passing(0,1,0)
Are you referring to :
void Passing(int a, int b = 1, int c = 0)
then
Passing (3) is equivalent to Passing(3,1,0)
?
Thank you very much vlad from moscow for your quick reply!