Are these two functions equal?

In C++, while defining two functions, can those two functions have the same variables as formal arguments?

  • consider two different function calls functionA(3,5); functionB(8,9); while defining those functions, can they both have the same variables m and n as formal arguments? Like... void functionA(int m, int n) { function body; } void functionB(int m,int n) { function body; }

  • Answer:

    yes you can. there should be no problem. try this program if you want. #include<iostream> #include<conio.h> using namespace std; void add(int a,int b) { cout<<a+b<<endl; } void sub(int a,int b) { cout<<a-b<<endl; } int main() { add(3,4); sub(3,4); getch(); return 1; }

Maya at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

it is acceptable.. scope is local

Abdul Nawaf

No. In C++, they should differ either in number of arguments or type of arguments or both.Function return type is also not considered. The following is also not acceptable. int functionA(int m, int n) { function body; } void functionA(int m,int n) { function body; }

James Bond

yes you can. First m and n are local to functionA and second m and n are local to functionB.

s taru

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.