c - b and *b works in argument list of my function exactly same. What is the difference then? -


this question has answer here:

i use swapcardsrandomly(b) when tried swapcardsrandomly(*b) program still works without problem.

what difference then?

/* *shuffles cards randomly */ void shuffle( int b[][13] ) {      int counter;     int rand1 = rand() % 4;     int rand2 = rand() % 13;      b[rand1][rand2] = 1;      counter = 2;     while ( counter < 53 )     {         rand1 = rand() % 4;         rand2 = rand() % 13;          while ( b[rand1][rand2] != 0 )         {             rand1 = rand() % 4;             rand2 = rand() % 13;         }          b[rand1][rand2] = counter++;     }     swapcardsrandomly( b ); }  //for better shuffling swap elements randomly void swapcardsrandomly( int m[][13] ) {      int temp;     int rand1;      int rand2;      ( = 0; < 4; i++ )     {         ( j = 0; j < 13; j++ )         {             rand1 = rand() % 4;             rand2 = rand() % 13;              temp = m[i][j];             m[i][j] = m[rand1][rand2];             m[rand1][rand2] = temp;          }     } } 

in multi-dimensional array first element, , pointer first row have same address. because first element of array has same address array. so, in case, b points first element of int [][13] array , *b points first element of int [13] array happens first row of int [][13] array.

the next question why lets pass *b swapcardsrandomly when expects int [][13] argument. answer arrays, including multi-dimensional arrays, not proper types in c, when passed in manner treats them way interpret pointer.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -