0

Let us suppose the following program:

#include <stdlib.h>
int main()
{
  int a,b,;
  scanf("%d",&a);
  scanf("%d",&b);
  c = func(a,b);
  printf("%d",c);
  return 0;
}

int func(int a, int b)
{
  return a+b;
}

Now, let us suppose the following options for defining a prototype for the function "func".

Option 1:

int func(int a, int b);

Option 2:

int func(int , int);

What are the differences between option 1 and 2? They have exactly the same effects?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Zaratruta
  • 2,097
  • 2
  • 20
  • 26
  • 1
    https://stackoverflow.com/questions/8174886/put-name-of-parameters-in-c-function-prototypes – pzaenger Oct 06 '18 at 20:57
  • The prototype doesn't need to mention the names, only the types. – Weather Vane Oct 06 '18 at 20:57
  • 1
    Possible duplicate of [Put name of parameters in C function prototypes?](https://stackoverflow.com/questions/8174886/put-name-of-parameters-in-c-function-prototypes) – kiran Biradar Oct 06 '18 at 21:00
  • They're the same. However `int func(int parcel1, int parcel2);` *(you can use `int func(int a, int b) { /*...*/ }` for the definition)* is more descriptive. – pmg Oct 06 '18 at 21:03

2 Answers2

3

1 and 2 are exactly the same. The C compiler allows you to put in parameter names, but they are arbitrary: subject to their being legal names (for example, they can't be keywords, or contain a leading double underscore), the compiler will ignore them.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
1

The two options are the same, but the first one gives more information on what the parameters are (for more advanced functions).

clang-tidy has a rule that warns against writing option 2.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62