| | |
Quick Question: Pointer to a 2D array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Sorry, but
Probably, coveredinflies wants to pass an array as a function argument so right example is most likely
But it's not the same as
A pointer to an array is a funny thing in C and C++. Array name is implicitly converted in a pointer in all contexts except argument of sizeof operator. So no need in pointers to arrays.
But we can't pass 2D array declared as a[...][...] in the second foo because of its argument type is a pointer to a pointer to char, but not an implicit pointer to 2D array with 255 columns...
char* ay[][255] declares 2D array of pointers to char.Probably, coveredinflies wants to pass an array as a function argument so right example is most likely
C++ Syntax (Toggle Plain Text)
void foo(char ay[][255] );
C++ Syntax (Toggle Plain Text)
void foo(char **ay);
But we can't pass 2D array declared as a[...][...] in the second foo because of its argument type is a pointer to a pointer to char, but not an implicit pointer to 2D array with 255 columns...
>>Sorry, but char* ay[][255] declares 2D array of pointers to char.
You are right -- I should not have included the star.
We don't know how the OP declared the 2d array, so it could be either method.
You are right -- I should not have included the star.
We don't know how the OP declared the 2d array, so it could be either method.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Impossible? I would call the below a 2d array.
C++ Syntax (Toggle Plain Text)
int main() { const int rows = 25; const int columns = 255; char ** array = new char*[rows]; for(int i = 0; i < rows; i++) array[i] = new char[columns]; foo(array); }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jul 2008
Posts: 32
Reputation:
Solved Threads: 0
Thanks this is what I needed. Pretty obvious in hindsight. Sorry for any ambiguity in original post.
![]() |
Similar Threads
- class question (C++)
- Quick Array Return Question (C++)
- problem with phonebook program (C)
- C: - reading in from text (C++)
- pointer to a string, question. (C++)
- Seg Fault ~ Linked List Delete (C)
Other Threads in the C++ Forum
- Previous Thread: Is this good programming practice? or is it problematic?
- Next Thread: Calculate large Factorials
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets







)...