ポインターを使用して、ある 2 次元配列の内容を別の配列にコピーしようとしていました。この簡単なテスト プログラムを作成しましたが、セグメンテーション違反が表示されますが、まだ確固たる理由を見つけることができません。
#include <stdio.h>
void main(){
int m[2][3]={
{2,3,4},{5,6,7}
};
int *p=m;
int *n;
int i,j;
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf("%d \t", *(p+3*i+j));
printf("Debug here\n");
*(n+3*i+j)=*(p+3*i+j);
}
printf("\n");
}
}
// Output:
// 2 Debug here
// Segmentation fault (core dumped)