Apr 24, 2016 at 6:46am UTC
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
Apr 24, 2016 at 8:03am UTC
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 Apr 24, 2016 at 8:19am UTC
Apr 24, 2016 at 2:10pm UTC
You should probably pass the number of elements in the array too:
int *fun_array(int arr[], size_t size);