pass 2-d array to function in turboo c++

Pages: 12
Muhammad Abdullah wrote:
why dont you fix the error?

Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

If your problem is "I don't understand a thing", then you should go back to basics and study again.

You have posted some code. We have asked simple questions about it. You, as the author of the code should be able to answer the questions. If you, the person who wrote the code, have no idea what the code does, then how could you possibly learn from or understand code written by someone else?


And once again: please do use code tags when posting code.
See http://www.cplusplus.com/articles/jEywvCM9/


Your original question is: "How to pass an array to function?"

In your first thread I did give you a link to page that discusses that. Within it is written:
The answer is that the C compiler does a little something behind your back. It knows that whenever you mention an array name in an expression, it (the compiler) generates a pointer to the array's first element. Therefore, it knows that a function can never actually receive an array as a parameter. Therefore, whenever it sees you defining a function that seems to accept an array as a parameter, the compiler quietly pretends that you had declared it as accepting a pointer, instead.

In other words, when you write:
1
2
3
4
5
6
void foo( int array[] );

int main() {
  int bar[5];
  foo( bar );
}

it is as if you had written
1
2
3
4
5
6
void foo( int * array );

int main() {
  int bar[5];
  foo( bar );
}

What do you think, expanding on the above example, could a pointer to pointer be a type that matches a 2D array in function argument context? That should be easy to test.
Topic archived. No new replies allowed.
Pages: 12