69,371
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
/*
some_fun有两个传出参数row和col,返回值为数组地址
*/
int* some_fun(int* row, int* col)
{
int k = 0;
int* arr = (int*)malloc(3 * 5 * sizeof(int));
for(int i = 0; i < 3; ++i)
{
for(int j = 0; j < 5; ++j)
{
*(arr + i * 5 + j) = k++;
}
}
*row = 3;
*col = 5;
return arr;
}
int main(int argc, char** argv)
{
int row, col;
int* arr = some_fun(&row, &col);
for(int i = 0; i < row; ++i)
{
for(int j = 0; j < col; ++j)
{
printf("%d\t", *(arr + i * 5 + j));
}
printf("\n");
}
free(arr);
return 0;
}
typedef struct {
int x;
int y;
}location;
void function(int* array, int* x, int* y)
{
//...
}