When we declare we use
But when we use the function, it goes:
string s = foo()
void just a convention? Does it do anything in particular different from
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.Sign up to join this community
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.