![]() |
| ||
| Passing 2D Array of Pointers into a function Dear All, I am facing a problem in passing 2D array of pointers to a function. can any one give some suggestions on this. 1. How the Declaration fo the function should be ? 2. How to pass 2D array of pointers to that function? 3. How to access the array elements. The aray declaration is *ptr[2][3] = { {"AA","XX","FF"}, {"DD","QQ","EE"}, }; It would be great helpful for me,since I am struggling with this one |
| ||
| Re: Passing 2D Array of Pointers into a function If you're struggling, duplicate your declaration: void foo ( int *arg[2][3] );Within foo, you use arg just as you would use ptr unless you're trying to use sizeof, in which case you probably won't get the result you want. |
| ||
| Re: Passing 2D Array of Pointers into a function Quote:
Hi, Thanks for your reply. But I have diffrent types of 2D array of pointers which varies rows and columns size, So in the function declaration/definition I can not specify the rows and columns size. So I am trying for an alternative. |
| ||
| Re: Passing 2D Array of Pointers into a function >So in the function declaration/definition I can not specify the rows and columns size. Then you can't use an array. The size of the first dimension may be omitted, but the others are required, and the size of an array dimension must be a compile-time constant. If you want to pass a two dimensional array of any size to a function, you use dynamic memory: #include <stdlib.h>You have more options in C++, but you neglected to mention what language you're using. |
| ||
| Re: Passing 2D Array of Pointers into a function here is how you initialize the function and pass the values
|
| ||
| Re: Passing 2D Array of Pointers into a function Maybe you want to take a look at my code: #include <iostream> |
| All times are GMT -4. The time now is 7:59 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC