In C, how does the declaration int f(); differ from int f(void);?
Correct answer
C. The first declares no prototype, so any arguments are accepted unchecked
21 views
C. The first declares no prototype, so any arguments are accepted unchecked
21 views
An empty parameter list is an old-style declaration with no prototype, so calls with any number and type of arguments are not checked against it. Writing (void) states explicitly that the function takes no arguments and makes the compiler diagnose mismatched calls. In C++ the two forms are equivalent, and C23 changed f() to mean f(void), which is why older textbooks and newer compilers disagree.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.