0

I don't know why if how known pls tell me

#include <stdio.h> int main(){ int sam[3],i; sam[1] = 5; sam[2] = 5; sam[3] = 6; for (i=0;i<3;i++){ printf("%d\n",sam[i]); } } (unexpected)the answer is 4200656 5 5 (expect) 5 5 6

7th Feb 2018, 8:55 AM
Maco Billioat
Maco Billioat - avatar
2 odpowiedzi
+ 3
An array is zero-index. So it start counting by 0. int main() { int sam[3],i; sam[0] = 5; sam[1] = 5; sam[2] = 6; for (i=0;i<3;i++) { printf("%d\n",sam[i]); } } you'll be fine
7th Feb 2018, 9:04 AM
sneeze
sneeze - avatar
0
thank you so mush @sneeze
7th Feb 2018, 9:09 AM
Maco Billioat
Maco Billioat - avatar