How to pass an array to function as a perimeter .

I want to pass an array to function which further make changes in an array and it will have to return that array through that function. I forgot syntax anyone can tell.

int fun_array([])

{
for (int i=0;i<=array size-1 ;i++)
cin>>arr[i];


return arr;
}
i want this type of function
Do something like this.

int *fun_array(int arr[] ) ///note the '*' sign here for returning an array
{
///Do whatever you want with arr here

return arr ; ///returning an array
}

int main()
{
int ar[5] ;

int *iar=fun_array( ar ) ; ///passing and receiving the array

cin.get() ;
return 0 ;
}

you can access the iar pointer using the array syntax.

for( int i=0 ; i<5 ; i++ )
{
cout<< iar[i] ;
}

regards!
Last edited on
You should probably pass the number of elements in the array too:
int *fun_array(int arr[], size_t size);
Topic archived. No new replies allowed.