Return array from function - objective C
Objective C programming language does not allow to return an entire array as an argument to a function. However, you can return a pointer to an array by specifying the array's name without an index.
If you want to return a single dimensional array from a function, you would have to declare a function returning a pointer as in the following example:
Second point to remember is that objective C does not advocate to return the address of a local variable to outside of the function so you would have to define the local variable as static variable.
Now Consider the following function , which will generate 10 random numbers and return them using an array and call this function as follows:
If you want to return a single dimensional array from a function, you would have to declare a function returning a pointer as in the following example:
int * myFunction ()
{
.
.
}
{
.
.
}
Second point to remember is that objective C does not advocate to return the address of a local variable to outside of the function so you would have to define the local variable as static variable.
Now Consider the following function , which will generate 10 random numbers and return them using an array and call this function as follows:
No comments: