Home >Backend Development >C++ >How to Convert a 2D Array to a Pointer-to-Pointer?
Converting a 2D Array to a Pointer-to-Pointer
Your request to convert a 2D array to a pointer-to-pointer raises compatibility issues. These two data types have distinct semantics, making a direct conversion impractical.
However, if it's essential in your application, you can employ an intermediate step to bridge the semantic gap:
Activity solution[a][b]; // Create an array of pointers to each row of the 2D array Activity *solution_rows[a] = { solution[0], solution[1] /* and so on */ }; // Assign the pointer-to-pointer variable to the row index array Activity **mother = solution_rows;
This intermediate array, solution_rows, serves as a stepping stone between the 2D array and the pointer-to-pointer. Now, accessing mother[i][j] will effectively access solution[i][j].
The above is the detailed content of How to Convert a 2D Array to a Pointer-to-Pointer?. For more information, please follow other related articles on the PHP Chinese website!