Basically, I have an array of char* that I want to pass and modify in this function, so I pass in a pointer to an array of char*. That is, I want to pass a pointer to char* arr[]. What is the difference between the two?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As always, http://cdecl.org is your friend:
char * (*arr)[]– “declare arr as pointer to array of pointer to char”char *** arr– “declare arr as pointer to pointer to pointer to char”These are not the same. For a start, the first is an incomplete type (in order to use a pointer to an array, the compiler needs to know the array size).
Your aim isn’t entirely clear. I’m guessing that really all you want to do is modify the underlying data in your array of
char *. If so, then you can just pass a pointer to the first element:If you really want to pass a pointer to an array, then something like this would work:
For more info on the important difference between arrays and pointers, see the dedicated chapter of the C FAQ: http://c-faq.com/aryptr/index.html.