what is this syntax for double x[]?
Is it a C way to declare an array?
If I have a function like
void evaluate(double x[], double *f)
{
// evaluate
}
Can I pass a parameter x with any length?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A parameter of array type behaves exactly like it is a pointer. You can not truly pass an array as a function argument. However, this syntax gives the illusion that you can for the sake of readability. So your function is equivalent to:
From §8.3.5/5 of ISO/IEC 14882:2011:
An expression that denotes an array will decay to a pointer to its first element, so you can still do this:
From §4.2:
So yes, you can indeed pass an array of any length. In reality, you are just passing a pointer to the first element. You will, however, need to pass the length of the array as well, if you need it.