You have defined arr as arr[MAX_NUM][MAX_SIZE], so you can only access MAX_NUM - 1 and MAX_SIZE - 1 elements. So using arr[MAX_NUM] is out of bounds. Remember arrays in C start at 0 and end at size -1.