-1

I was recently working on 2-D arrays in C. My code looks something like this -

#include<stdio.h>

void main()
{
    int A[3][3];
    int i,j;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            scanf("%d",&A[i][j]);
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            printf("%d ",A[i][j]);
        printf("\n");
    }
}

The input I gave was -

2 1 3

1 3 2

1 2 3

But I don't know why the C(GCC 6.3) compiler tends to throw a run-time error. The code seems to work fine and matrix A shows everything perfectly while display.

Shubham Jain
  • 31
  • 1
  • 6

1 Answers1

0

The runtime error, NZEC stands for Non Zero Exit Code.

Your program should return 0 in order to indicate that it ran successfully.

But it does not return anything because you have used void main().

Solution:

  1. Change void main() to int main()

  2. Add a return 0; at the end of main (optional)

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
  • @EricPostpischil *Re: "Unless you know that OP’s C implementation behaves differently"*. I know it because he used `void main`, which is not Standard C. – Ardent Coder Apr 04 '20 at 14:05