Doubt regarding the passage of parameters

1

In the following code, in line 5, the foo1t function calls the foo1 function by passing two parameters to it, however, the foo1 function has only one parameter. Is this possible or is the code wrong? If it is possible, I would like an explanation.

1   int foo1t(int n, int resp) {
2       if (n <= 1) {
3           return resp;
4       } else {
5           return foo1(n-1, n*resp);
6       }
7   }
8
9   int foo1(int n) {
10      return foo1t(n, 1);
11  }
    
asked by anonymous 23.06.2017 / 00:59

1 answer

3

No, the code is wrong. Probably the inductive step should be return foo1t(n-1, n*resp);

Functions in C can be declared "without parameters", and can have a variable amount of parameters (the variable functions, such as printf() ), but if the parameters are declared they can not be called with a wrong number of parameters. In the case of pointers or integers, you can even pass an integer in place of a pointer or vice versa, but the compiler will typically issue at least one warning.

    
23.06.2017 / 01:07