Re: [問題] 怎樣把二維陣列傳給另一個function
看板C_and_CPP (C/C++)作者snowlike (snowlike)時間16年前 (2009/03/14 21:20)推噓1(1推 0噓 2→)留言3則, 2人參與討論串4/6 (看更多)
#include <cstdio>
#include <cstdlib>
void sub(int *a, int b, int c) {
for(int i=0;i<b;i++) {
for(int j=0;j<c;j++)
printf(" %d",a[i*c+j]);
printf("\n");
}
}
int main() {
int x, y;
scanf("%d %d", &x, &y);
int *ary=static_cast<int*>(malloc(x*y*sizeof(int)));
for(int i=0;i<x*y;i++)
ary[i]=i;
sub(ary, x, y);
free(ary);
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.229.38.101
→
03/14 21:23, , 1F
03/14 21:23, 1F
推
03/14 21:27, , 2F
03/14 21:27, 2F
→
03/14 21:49, , 3F
03/14 21:49, 3F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章