Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c language] Answer to "what is optional in a function declaration" is only correct for C23 #7094

Open
uap-universe opened this issue Jan 3, 2025 · 0 comments

Comments

@uap-universe
Copy link

uap-universe commented Jan 3, 2025

The following answer is only correct for C23.

#### Q13. What is optional in a function declaration?
- [ ] data type of parameters
- [ ] return type of function
- [x] parameter names
- [ ] number of parameters
[Reference](https://www.cprogramming.com/tutorial/c/lesson4.html)

Before C99, all four have been optional. Starting with C99, the parameter names and the number of parameters are still optional.

The following declaration declares the function with an unknown number of parameters (but without declaring a prototype):

int f();

With C23 this was changed to be equivalent to the following declaration:

int f(void);

In C17, for example, this is perfectly valid while it does not compile with C23:

int f();

int f(int x) { return x*2; }

See also: cppreference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant