H.S. wrote:

> Hello,
> 
> I don't seem to recall at the moment so I thought of trying you all
> guys. In C++, do the names of arguments in a function declaration (or
> prototype) need to match the names of the arguments in function
> definition?
> 

They don't need to match (either in C or in C++). The function declarations
are more for verifying whether you are passing the "right type of
arguments". The compilers do not check the names. In fact, you can even
omit the variable names altogether in the function declarations. For
example, the following code is completely valid.

#include <iostream>

using std::cout; using std::cin;
using std::endl;

double sum(const double& , const double&);

int main() {
        double a, b, c;

        cout << "Enter two numbers" << endl;
        cin >> a >> b;
        c = sum(a, b);

        cout << a << " + " << b << " = " << c << endl;
        return 0;
}

double sum(const double& p, const double& q) {
        return(p+q);
}

hth
raju
-- 
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to