Skip to content

Instantly share code, notes, and snippets.

@K-atc
Created June 5, 2014 07:17
Show Gist options
  • Save K-atc/3b18af8039e921ddf011 to your computer and use it in GitHub Desktop.
Save K-atc/3b18af8039e921ddf011 to your computer and use it in GitHub Desktop.
ポインタ配列を使わない普通の2次元配列arrを関数の引数で渡したときの、その関数でのarrの扱い方を確認した。
void print(int *arr){
int i, j;
for(i = 0; i < 3; i++){
for(j = 0 ; j < 3; j++){
printf("%d\n", arr[3*i+j]);
}
}
}
int main(){
int i, j, num = 1;
int arr[3][3];
for(i = 0; i < 3; i++){
for(j = 0; j < 3; j++){
arr[i][j] = num;
num++;
}
}
print(arr);
return 0;
}
/*
outputs:
1
2
3
4
5
6
7
8
9
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment