When we declare we use int foo(void);

But when we use the function, it goes: string s = foo()

Is void just a convention? Does it do anything in particular different from ()?


First we've been taught to use (void) when declaring a function and use () when calling, using a function...

Apart from that,

void foo() means "a function foo taking an unspecified number of arguments of unspecified type", i.e. don't assume anything about the arguments of foo; all parameter checking is turned off. This special meaning is intended to permit older C programs to compile with new compilers. But it's a bad idea to use it with new programs.

void foo(void) means "a function foo taking no arguments"

If the function takes arguments, declare them; if it takes no arguments, use void.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .