NeverSayNever's blog

By NeverSayNever, 10 years ago, In English

void init(bool A[MAX][MAX],bool res[MAX][MAX]){

for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
       res[i][j] = A[i][j] = 0;
/**
    memset(res,0,sizeof(res));
    memset(A,0,sizeof(A));
**/
for(int i=0;i<n;i++)
    A[P[i]][i] = 1,res[i][i] = 1;

}

Here is the code snippet. If i used the commented part instead of two loops it fails and produce a weird output.

here is the full code link and problem link. http://ideone.com/cdsWYE http://www.spoj.com/problems/PDECODE/

Please if anyone can help then suggest me a valid reason for this.

  • Vote: I like it
  • +15
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it +29 Vote: I do not like it
»
10 years ago, # |
Rev. 3   Vote: I like it +18 Vote: I do not like it

replace

void init(bool A[MAX][MAX],bool res[MAX][MAX]){

with

void init(bool (&A)[MAX][MAX],bool (&res)[MAX][MAX]){

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    This will not make nay difference because arrays are always passes by pointers / references .

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I don't understand. What exactly does it do?