#2D array callee and caller (This is a Reversi Homework)
1 messages · Page 1 of 1 (latest)
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.
There are a few things to know.
- 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[])
- and 3. will be the same as
int *paramjust different syntax.
When you pass arrays to functions they decay to pointers to the first element of the array. (Thats also whysizeofwont be same anymore)
So in your code you would have to do print_board(board)
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’
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?
Did you include the header where it’s declared/defined?
OK
I have not include the right-hand side file
thank you
@hard tree Has your question been resolved? If so, run !solved :)
!solved
Thank you and let us know if you have any more questions!
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