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
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:
- 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.