Segment Fault

When run it, segment fault.
What is wrong?

#include <stdio.h>
#include <stdlib.h>
 
const int max =20;


//****************************************************
//     Input Matrix 
//****************************************************

void inMatrixAA(int *AA, int row, int col)
{     int i,j;
        for( i = 0; i<row; i++)
           {
               for( j = 0; j<col; j++)
                 scanf("%d",AA+i*max+j);
           }   
}

//*****************************************************
//   Print Matrix 
//***************************************************** 

void prMatrix( int *AA, int row, int col) 
{       int i,j;
           for(i =0; i<row; i++)
              {
                 for(j = 0; j<col; j++) 
                  printf("%d\n",*(AA+i*max+j));
              }
}

int main(int argc,char *argv[])
   {
       int m,k;
       int A[max][max];
       int ii,jj;
        for (ii = 0; ii<max;ii++)
         {
           for(jj =0;jj<max;jj++)
            {
              A[ii][jj] = 0;
            }
         }            
       printf("Enter values for m, k");
       scanf("%d",&m);
       scanf("%d",&k);

       
       printf("Input Matrix A");
       inMatrixAA(&A[0][0], m, k);

       printf("Print Matrix A");
       prMatrix(&A[0][0], m, k);
   
   }

i wonder,
first this would not compile,

you need to mention an integral constant expression

may be you would have thought providing an #define value to max

#define max 20

I tried to compile this ealrier and found even more issues. I just gave up. If it really compiles for the OP, she/he's got a very interesting compiler. Maybe a C++ compiler being used for C.

Tried to compile this a few hours ago on HP-UX 11.11. Being a non ANSI compliant compiler, the thing puked on so many points, I didn't even try to fix the problems.

I dare to rectify ur code though I agree with others that ur code shouldn't compile.

#include <stdio.h>
#include <stdlib.h>
#define max 20

//****************************************************
//     Input Matrix
//****************************************************

void inMatrixAA(int AA[max][max], int row, int col)
{     int i,j;
        for( i = 0; i<row; i++)
           {
               for( j = 0; j<col; j++)
                 scanf("%d",&AA[j]);
           }
}

//*****************************************************
//   Print Matrix
//*****************************************************

void prMatrix( int AA[max][max], int row, int col)
{       int i,j;
           for(i =0; i<row; i++)
              {
                 for(j = 0; j<col; j++)
                   printf("%d\n",AA[j]);
              }
}

int main(int argc,char *argv[])
   {
       int A[max][max];
       int m,k;
       int ii,jj;
        for (ii = 0; ii<max;ii++)
         {
           for(jj =0;jj<max;jj++)
            {
              A[ii][jj] = 0;
            }
         }
         printf("Enter values for m, k\n");
       scanf("%d%d",&m,&k);
       printf("Input Matrix A");
       inMatrixAA(A, m, k);
       printf("Print Matrix A");
       prMatrix(A, m, k);
       return 0;
   }

It shall compile.
I would like u to advise :
1) In C use constants expressions in specifying the size of array
U may use preprocessors like #define though.
2) Take care with pointers (if u r passing pointer to pointer in
invoking the function then keep the same in defintion of the function)

Hope these help u.

Good work, Rakesh Ranjan. I like your code. As for zhshqzyc's code, while I do dislike the techniques being used, I don't find the code to as alien as everyone is indicating. I see two items that violate Ansi C: the // style one line comments and the use of "const int max =20;" instead of "#define max 20". Both of these are legal in C++. But also there is a new C standard out called C99. I don't have access to a C99 compiler, but I strongly suspect that the code is legal C99. And for the record, gcc accepts the code as well. When I run the code, it more or less works for me. I also dislike the output format and will never regard output a 2 dimensional array as a column "correct". The coding techniques being used invite the programmer to confuse rows and columns and that is what happened here. I used square matrices to avoid any problems.

Compiling the code on a compiler that does not understand the one line comment style results in a lot of errors. This is because a comment like:
//******
has the beginning of a old c style comment starting with the second character. The compiler has a very hard time recovering from that error. If your C compilers are freaking out, I think that is the principal reason. Even gcc with an -ansi switch gave up, no -pedantic switch needed.

I have a CC native compiler on solaris10..it works perfectly on it..and i dont think that ..const int max =20;" instead of "#define max 20 is required...C++ ANSI standrads dont prohibits it.

your code can be further optimised to have a common function as below instead of having two seperate functions

#include <stdio.h>
#define max 20
int glb=0;

void comMatrixAA(int AA[max][max], int row, int col)
{     int i,j;
       for( i = 0; i<row; i++)
          {
              for( j = 0; j<col; j++)
              {
                !glb && scanf("%d",&AA[j]);
                glb && printf("<-:-> %d\n", AA[j]);
              }
          }
        glb=!glb;
}

int main(int argc,char *argv[])
  {
      int A[max][max];
      int m,k;
      int ii,jj;
       for (ii = 0; ii<max;ii++)
        {
          for(jj =0;jj<max;jj++)
           {
             A[ii][jj] = 0;
           }
        }
       printf("Enter values for m, k\n");
      scanf("%d%d",&m,&k);
      printf("Input Matrix A");

      comMatrixAA(A, m, k);
      printf("Print Matrix A");
      comMatrixAA(A, m, k);
      return 0;
  }

besides that what is the need to include stdlib.h

Elegant piece of code!! I really appreciate the way u join the two functions. And yes stdlib really didn't mean to be there. I just skipped the non-essential include part and concentrated on the part where zhshqzyc might be erring. But on the combining of the two functions I would like to make a small comment though ur code does what is expected of the code but this might not be the real intension of the programmer, may be he was presenting it in most simple way. Although here the calls to get input and display results are sequential but in real problem he might be facing he may be calling input once and printing the elements twice or thrice so it doesn't make sense to combine two functions with two different functionality.
Further I quote

I really couldn't figure it out how this tweak of urs ensured code optimization.
The calls are two separate calls and overhead of switching from main to ur function is also incurred twice (as it might have been, had there been two functions as before) rather I feel that ur induction of a global variable 'glb' makes the code more inefficient for most modern C compilers alias local variables to CPUs register's or SRAM but can't do so with global variables. Furthermore, if all variables in a given scope are local, then an optimizing compiler, can forgo maintaining the variable outside the scope, and therefore has more simplification optimization opportunities than with global.
Add to it the time in evaluation of logical operators.
The only way I feel ur code can be made really efficient might be by declaring the function static making the call a fixed function call.

Please rectify me if I've gone wrong somewhere.

Yes,

It was just a tweak or work around with the legacy of code.
No way its related with the performance of the code.

Its well apted for code with serialized functions, when they are common in call-sequence, generalized functionality- this would serve as an approacher.