fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. // 2D 배열 (3행 4열)
  5. int arr[3][4] = {
  6. {1, 2, 3, 4},
  7. {5, 6, 7, 8},
  8. {9, 10, 11, 12}
  9. };
  10.  
  11. // 포인터 배열 (각각 행의 시작 주소를 저장)
  12. int *ptr_arr[3];
  13.  
  14. // 각 행의 시작 주소를 포인터 배열에 저장
  15. for(int i = 0; i < 3; i++) {
  16. ptr_arr[i] = arr[i];
  17. }
  18.  
  19. // 포인터 배열을 통해 2D 배열을 출력
  20. printf("2D 배열의 값들: \n");
  21. for(int i = 0; i < 3; i++) {
  22. for(int j = 0; j < 4; j++) {
  23. printf("%d ", *(ptr_arr[i] + j)); // 포인터를 사용해 각 값 출력
  24. }
  25. printf("\n");
  26. }
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
2D 배열의 값들: 
1 2 3 4 
5 6 7 8 
9 10 11 12