1

Recently I read the "K&R" book, where it is written that, if we don't have arguments in our function, we have to write "void" in brackets to make the program work correctly, with old standards too. Do we need it these days?

Example:

int foo(void)
{
/*...*/
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Skiv Hisink
  • 164
  • 2
  • 12

1 Answers1

2

Assuming you are talking about the declaration of your function (rather than calling it - see below), then the following (from here), should answer your question:

The declarators f() and f(void) have different meaning: the declarator f(void) is a new-style (prototype) declarator that declares a function that takes no parameters. The declarator f() is an old-style (K&R) declarator that declares a function that takes an unspecified number of parameters (unless used in an old-style function definition)

However, when calling a function, you cannot include the void keyword: int p = func(void); won't compile - you have to use int p = func();.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83