I teach C to absolute beginners and I have noticed that some of my students get the notion to use the same name for the function and a local variable in the function. I think it's goofy and would prevent recursion.
Here's an example:
int add2numbers (int a, int b) { /* Tested on Mac OS X with gcc */
int add2numbers = a + b;
return add2numbers;
}
The way I understand how it works is that the variable is in the local scope of the function, and the function is in the global scope.
So, the questions...
- Am I understanding this correctly?
- Where the h*** are they getting that idea from?
Thanks