If I can pass in an array of a known size:
void fn(int(*intArray)[4])
{
(*intArray)[0] = 7;
}
why can’t I return one:
int intArray[4] = {0};
int(*)[4] fn()
{
return &intArray;
}
here, the “)” in “(*)” generates “syntax error : )”.
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.
The
[4]goes after the function name, just like it goes after the variable name in a variable definition:Since this is very obscure syntax, prone to be confusing to everybody who reads it, I would recommend to return the array as a simple
int*, if you don’t have any special reason why it has to be a pointer-to-array.You could also simplify the function definition with a typedef: