Difference between foo(void) and foo()
Source: http://stackoverflow.com/ Problem: Consider these two function definitions void foo (){ ... } void foo ( void ){ ..... } What is the difference between these two functions? Hint: The answer depends whether this is C code or C++ code. Solution: Highlight the part between the * symbols for the answer. * In C++ there is no difference: both declare a function taking no arguments. In C they differ. void foo(void) declares a function taking no arguments - calling foo(42) is a compile error. void foo() declares a function with an unspecified (unprototyped) parameter list: the compiler accepts calls with any arguments, e.g. foo(66) compiles fine and the argument is simply ignored. So in C, foo() means "parameters not specified", not "no parameters". (Note: in a *definition*, void foo(){...} defines a no-argument function, but calls to it are still unchecked without a prototype; writing (void) is the correct habit in C.) Solution by DETERMINANT from th...