Home c++ How to transfer a pointer to a two-dimensional array function?

How to transfer a pointer to a two-dimensional array function?

Author

Date

Category

So it does not work.


Answer 1, Authority 100%

It is necessary when an function declarations indicate the size of the smaller dimension of the array:

void vqvod (int arr [] [m]) {
  ... // here cycle
  cout & lt; & lt; arr [i] [j];
  ...
}

or pointer:

void vqvod (int * arr [m]) {
  ... // here cycle
  cout & lt; & lt; arr [i] [j];
  ...
}

with simple pointer:

void vqvod (int * arr) {
   ... // here cycle
   COUT & LT; & LT; * (Arr + I * M + J); // Stritch for long rainwood
   ...
}
INT MAIN () {
...
  VQVOD ((INT *) A); // This is how it is necessary to call a function
...
}

Answer 2, Authority 22%

I transmit a matrix to a function like this:

int lines = 3, columns = 4;
Double ** Matrix = New Double * [Lines];
for (int i = 0; i & lt; lines; i ++)
  Matrix [i] = New Double [columns];

A, then, transfer to function:

fun (Matrix, Lines, Columns);

Prototype function:

void fun (double **, int, int);

Do not forget to free up memory:

for (int i = 0; i & lt; lines; i ++)
{
  DELETE [] MATRIX [I];
  Matrix [i] = 0;
}
DELETE [] MATRIX;
Matrix = 0;

If the MATRIX pointer does not appeal anymore, then
You can not assign 0 not.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions