Possible Duplicate:
howto return a array in a c++ method? 开发者_JAVA百科
How an array can be returned from a function in c++?please accomplish your answer with a simple example too if possible.thankx in advance.
Return a pointer to the start of the array, like:
int* getArray(int numElements) {
int* theArray = malloc(sizeof(int) * numElements);
return theArray;
}
...you can use it like:
int* myArray = getArray(3);
myArray[0] = 1;
myArray[1] = 2;
myArray[2] = 3;
//do this when you are done with it
free(myArray);
精彩评论