两种方法使用C语言的指针函数返回一个数组

*

 * To return the integer array from the function, you should:

 *     - Store the size of the array to be returned in the result_count variable

 *     - Allocate the array statically or dynamically

 *

 * For example,

 * int* return_integer_array_using_static_allocation(int* result_count) {

 *     *result_count = 5;

 *

 *     static int a[5] = {1, 2, 3, 4, 5};

 *

 *     return a;

 * }

 *

 * int* return_integer_array_using_dynamic_allocation(int* result_count) {

 *     *result_count = 5;

 *

 *     int *a = malloc(5 * sizeof(int));

 *

 *     for (int i = 0; i < 5; i++) {

 *         *(a + i) = i + 1;

 *     }

 *

 *     return a;

 * }

 *

 */

你可能感兴趣的:(C语言编程笔记)