I have an array int arr[5] that is passed to a function fillarr(int arr[]):
int fillarr(int arr[])
{
for(...);
return arr;
}
- How can I return that array?
- How will I use it, say I returned a pointer how am I going to access it?
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.
In this case, your array variable
arrcan actually also be treated as a pointer to the beginning of your array’s block in memory, by an implicit conversion. This syntax that you’re using:Is kind of just syntactic sugar. You could really replace it with this and it would still work:
So in the same sense, what you want to return from your function is actually a pointer to the first element in the array:
And you’ll still be able to use it just like you would a normal array: