454,955 Members | 1,275 Online Need help? Post your question and get tips & solutions from a community of 454,955 IT Pros & Developers. It's quick & easy.

 P: 13 Hey, I have been browsing the site for awhile and find it quite impressive. I couldn't find an article that quite helped me out. I was curious as how to change the following program into pointer notation. Replies are much appreciated. using namespace std; const int row = 4; const int col = 5; int findMax(int [row][col]); int findMaxC(int [row][col]); int main() { int nums[row][col] = {16, 22, 99, 4, 18, -258, 4, 101, 5, 98, 105, 6, 15, 2, 45, 33, 88, 72, 16, 3}; int rn, cn; for (rn = 0; rn < row; rn++) { for (cn = 0; cn < col; cn++) cout < max) { max = n[i][j]; } if (n[i][j] > maxrow) { maxrow = n[i][j]; } } cout <<"Maximum number in Row number " < maxcol) { maxcol = n[i][j]; } } cout <<"Maximum number in Col number " <
5 Replies

 Expert 100+ P: 469 What do you mean by converting to pointer notation? Do you want to use dynamic arrays instead of static arrays? Nov 5 '08 #2

 P: 13 Correct. I understand how to do it for one dimensional arrays, but don't have a clue for two dimensional arrays. Nov 5 '08 #3

 Expert 10K+ P: 11,448 FYI: I chopped off the hijacker; feel free to continue in your thread. kind regards, Jos (moderator) Nov 5 '08 #4

 Expert 100+ P: 469 A two dimentional array is, of course, an array of one dimensional arrays. To declare a two dimensional dynamic array, use two asterisks instead of one, then allocate space for a lot of one dimensional arrays: Expand|Select|Wrap|Line Numbers int **nums = new int*[row]; Then use a loop to allocate space for each of the one dimensional arrays separately: Expand|Select|Wrap|Line Numbers for (int i = 0; i < row; i++)     nums[i] = new int[col]; Deleting is similar to allocating; first delete the one dimensional arrays, then delete the array of arrays: Expand|Select|Wrap|Line Numbers for (int i = 0; i < row; i++)     delete[] nums[i]; Then: Expand|Select|Wrap|Line Numbers delete[] nums; Don't get these in the wrong order or you'll get a segmentation fault. By the way, it would be helpful if you used code tags if you are posting some of your code here again. Put [CODE] before the code and [/CODE] after it, so it shows up in a code box like the above code and the indentation is preserved. Thanks. I hope this is somewhat helpful. Nov 5 '08 #5

 P: 13 Thank you so much, that explained exactly what I needed. Also thank you for the embedded code information. Nov 5 '08 #6 