-1

So I get that a void function won't return a value, while a int one for example will return an integer. So void main(){} doesnt return, but int main(){return 0;} will return.

My question is, what is the difference between these 3 functions. I know the first one wont return a value, the second one will return an integer. But how about the third one? I know it returns an integer because I've tested it, so what does that (void) does? Why is is there? void main(){} int main(){return 0;}; int main(void){return 0;};

I'm a begginer so sorry if it sounded confusing... Thanks in advance!!

(The question is about the programming language C)

horsse
  • 107
  • 5

1 Answers1

0

Between the parenthesis are the parameters to the function.

In a function definition, the proper way to designate a function that takes no parameters is to simply specify void for the parameter list.

An empty parameter list (in a definition) is also a way of saying the function takes no parameters, however this syntax is considered deprecated and should not be used in new programs.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • Many implementations use a calling convention which is agnostic to the presence or absence of arguments beyond those specified. On such implementations, a single `int dummyHandlerInt() { return 0; }` function could be used as a safe default value for function pointers of all types that return `int`, whose default behavior should be to return 0 without side effects. The Standard would allow implementations to require the definition of a separate dummy function for every combination of argument types, since some calling conventions would require the existence of separate functions, ... – supercat Sep 06 '22 at 21:34
  • ...but many implementations allow programmers to avoid such needless verbosity. – supercat Sep 06 '22 at 21:35