1 개요[ | ]
- C언어 2차원 배열 파라미터로 넘기기
2 int a[3][3] ★★[ | ]
C
Copy
#include<stdio.h>
void print(int a[3][3]) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++)
{
printf("%d ", a[i][j]);
a[i][j] ++;
}
printf("| ");
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print(arr); // 1 2 3 | 4 5 6 | 7 8 9 |
print(arr);
}
Loading
3 int a[][3] ★★[ | ]
C
Copy
#include<stdio.h>
void print(int a[][3]) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) printf("%d ", a[i][j]);
printf("| ");
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print(arr); // 1 2 3 | 4 5 6 | 7 8 9 |
}
Loading
4 int (*a)[3] ★[ | ]
C
Copy
#include<stdio.h>
void print(int (*a)[3]) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) printf("%d ", a[i][j]);
printf("| ");
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print(arr); // 1 2 3 | 4 5 6 | 7 8 9 |
}
Loading
5 int* a[ | ]
C
Copy
#include<stdio.h>
void print(int* a) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) printf("%d ", *(a+i*3+j));
printf("| ");
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print((int*)arr); // 1 2 3 | 4 5 6 | 7 8 9 |
}
Loading
C
Copy
#include<stdio.h>
void print(int* a) {
int (*b)[3] = (void*) a;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) printf("%d ", b[i][j]);
printf("| ");
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print((int*)arr); // 1 2 3 | 4 5 6 | 7 8 9 |
}
Loading
6 void* a ★★[ | ]
C
Copy
#include<stdio.h>
void print(void* a) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) printf("%d ", *((int*)a+i*3+j));
printf("| ");
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print((void*)arr); // 1 2 3 | 4 5 6 | 7 8 9 |
}
Loading
C
Copy
#include<stdio.h>
void print(void* a) {
int (*b)[3] = a;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) printf("%d ", b[i][j]);
printf("| ");
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print((void*)arr); // 1 2 3 | 4 5 6 | 7 8 9 |
}
Loading
7 같이 보기[ | ]
편집자 Jmnote Jmnote bot 172.226.94.9
로그인하시면 댓글을 쓸 수 있습니다.