2014-02-25 2 views
-2

2D 행렬을 사용해야하지만 일부 할당 후에는 모든 것이 잘못되었습니다. 기본적으로 지침입니다. X 및 Y는 2 변수 함수임을2D 행렬에 값 할당

test0 :0 
test1 :0 
test2 :0 
test3 :0 
test4 :-1 
test5 :-1 
test6 :3 
test7 :3 

참고

int matA[1][1], matB[1][7], matRes[1][7]; 
    memset (matA, 0, sizeof (matA)); 
    memset (matB, 0, sizeof (matB)); 
    memset (matRes, 0, sizeof (matRes)); 
     printf("test0 :%d \n",matB[1][0]); 
    //matrice de fonction 
    matB[1][0]= 0; 
     printf("test1 :%d \n",matB[1][0]); 
    matB[1][1]= matB[0][2]= matB[0][3]= 0; 
     printf("test2 :%d \n",matB[1][0]); 
    matB[0][0]= matB[0][4]= matB[0][6]= matB[1][2]= matB[1][4]= matB[1][5]= 1; 
     printf("test3 :%d \n",matB[1][0]); 
    matB[0][1]= matB[0][5]= matB[0][7]= matB[1][3]= matB[1][6]= matB[1][7]= -1; 
     printf("test4 :%d \n",matB[1][0]); 
    //matrice d'entrée 
    matA[0][1]= matA[1][0] = 0; 
     printf("test5 :%d \n",matB[1][0]); 
    matA[0][0]= X; 
     printf("test6 :%d \n",matB[1][0]); 
    matA[1][1]= Y; 
     printf("test7 :%d \n",matB[1][0]); 

출력 :

여기서 코드이다.

+1

정확한 제목. –

+0

'int matA [1] [1]'은 1 행렬입니다. 그게 네가 정말로 원하는거야? –

+0

탭이 0으로 초기화됩니까? 0321 [0] [0] [1] –

답변

7
int matB[1][7]; 
matB[1][0]= 0; 

이것은 matB에 대한 유효한 인덱스가 아닙니다. 아마도 matA 또는 matRes에 사용 된 메모리와 겹칠 것입니다. 그래서 matA을 변경하면 matB[1][0]이 변경됩니다.

+0

오, 알았어. 내가 어떻게이 문제를 해결할 수 있는지 배울거야. 내가보아야 만하는 방식으로 알아 줘서 고마워! –