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:

    If they have the same function name; no --> As this means their signature is the same. If they have different functions names; --> Well, duh, yes! You call a function using its name, so it knows exactly to whom you are referring, whether a gazillion others have the same parameter list or not.

Maya at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Yes, they can. The variable names listed in the definition of a function are local to that function. The variables m and n in functionA are completely different from the ones in functionB. The way C++ handles arguments to functions is to push them onto the stack just before calling the function. The function references those arguments by using pointers to the stack area. As soon as the function exits, the stack is restored to its original position, so those variables would not be defined anymore.

Carl

Yes you can. Those variable names are local to the function. i.e. they have local scope. They start with the values passed to them in the function call. Since you are using call by value then any new value in those variables will not show up in the calling function.

roger

Y not?? the m & n in functionA is different from functionB . it has local scope. and you cannot access functionA's m&n in functionB

Abdul Nawaf

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.