#2D array callee and caller (This is a Reversi Homework)

1 messages · Page 1 of 1 (latest)

hard tree
#

I want to know what is the meaning of board[][N] , N means the size of the board
In fact, I want to know what is the meaning of blank bracket

twin coralBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

hidden phoenix
# hard tree I want to know what is the meaning of board[][N] , N means the size of the board...

There are a few things to know.

  1. When creating an array the compiler has to know the size at compile time.
    If you do this
int main()
{
int arr[] = {2,3,4};
return 0;
}

the compiler sets the size to 3 because it had that many initialisation parameters.
If you remove the = {2,3,4} this wont work anymore because the compiler doesnt know the size of the array.
You can parse an array to a function in multiple different ways
1.
void myFunction(int *param)
2.
void myFunction(int param[10])
3.
void myFunction(int param[])

  1. and 3. will be the same as int *param just different syntax.
    When you pass arrays to functions they decay to pointers to the first element of the array. (Thats also why sizeof wont be same anymore)
#

So in your code you would have to do print_board(board)

timid robin
#

Basically the first size in a multidimensional array can be avoided because it decays to a pointer

#

What effectively your 2d array becomes in the function is a pointer to an array

#

Read as ‘your 2d array decays to a pointer to its first element, which itself is an array’

hard tree
#

c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ben20\AppData\Local\Temp\ccw64rz5.o:reversi-game.c:(.text+0x64): undefined reference to `print_board(char (*) [8])'
collect2.exe: error: ld returned 1 exit status

do you know what should I do now?

timid robin
#

Did you include the header where it’s declared/defined?

hard tree
#

OK
I have not include the right-hand side file
thank you

twin coralBOT
#

@hard tree Has your question been resolved? If so, run !solved :)

hard tree
#

!solved

twin coralBOT
#

Thank you and let us know if you have any more questions!

hard tree
#

I also want to ask
I can type only one text like int x[N][N]={' X '}
Then, all N*N array can represent by 'X'

how can I do this
thank you

timid robin
#

You need to loop over all elements, using two nested loops

#

for (i to N)
for (j to N)
array[i][j] = ‘X’