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
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:
- Can Any Formal System Prove Its Own Consistency?Best solution by Mathoverflow
- How can I pass global variables into a function?Best solution by Stack Overflow
- Can I use a variable to name other variables?Best solution by Stack Overflow
- Any one know were i can sell a formal dress in duluth mn?Best solution by Yahoo! Answers
- What are the functions of vitamin C?Best solution by nytimes.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.