0
When vector 3 is 5 in size, vector 2[0] will receive, even though it already has an assigned value and without any command to do so, it receives the vector value 3[4]. Whether this occurs only when vector 3 is equal in size to 5. Does anyone know the reason.
#include<stdio.h>
int main(){
int um=0, dois=0, tres=0, c=0;
printf("tamanho vetor2: ");
scanf("%d", &dois);
printf("valores: \n");
int vetor2[dois-1];
for(c=0; c <= (dois-1); c++) vetor2[c] = 0;
for (c = 0; c <= dois-1; c++){
scanf("%d", &vetor2[c]);
}
//printf("vetor2[0]:%d\n", vetor2[0]);
printf("tamanho vetor3: ");
scanf("%d", &tres);
printf("valores: \n");
int vetor3[tres-1];
for(c=0; c <= (tres -1); c++) vetor3[c] = 0;
for (c = 0; c <= (tres-1); c++){
scanf("%d", &vetor3[c]);
}
printf("vetor2[0]: %d, vetor3[%d]: %d",vetor2[0], tres-1, vetor3[tres-1]);
printf("\n");
}
It is necessary to put the value 5, when the vector size is requested, to see this problem.