int foo (int argc, …) vs int foo() vs int foo(void) in C

前端 未结 4 1159
不思量自难忘°
不思量自难忘° 2021-01-13 02:17

So today I figured (for the first time admittedly) that int foo() is in fact different from int foo(void) in that the first one allows any

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-13 02:35

    In standard conform C, you have to use int foo(void) if the function does not accept any parameters.

    I guess it is compiler dependant what happens, when you pass arguments to a function with empty braces. But I don't think there is a way to access these parameters.

    As for main, the only standard conform (pure c) ways to write them are either int main(void) or int main(int argc, char **argv) (or char *argv[] which is the same).

提交回复
热议问题