Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: char** or c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 4136 of 4295
Post > Topic >>

Re: char** or char*** in function arguments?

by "Jim Langston" <tazmaster@[EMAIL PROTECTED] > May 4, 2008 at 03:06 PM

Pat wrote:
> What does it mean when a function argument contains multiple "*" - for
> example:
>
> /***************************************/
> int GetNameData(char*** faceName)
> {
> *faceNames = registeredFaceNames;
> return numOffaceNames;
> }
> /***************************************/
>
> or
>
> /***************************************/
> int AreValuesValid(char ** error, double * paramValues)
> {
> <statements>
> }
> /**************************************?
>
> ?
>
> I know a single "*" after a type designation makes it a
> "pointer-to-type", but what about multiple "*" (such as  char***  or
> char **  shown above)? What do those do?
>
> Also, so far I've only seen this used with "char" types.  Is this
> something specific to that type only?
>
> Thanks for any help.

A pointer to a pointer is usually used in C when when you want change the 
original pointer itself.  (In C++ you would probalby want to use a
reference 
to a pointer).

Parameters in C and C++ are passed by value, they are copied.  If you wish

to change the actual variable passed in you will need a pointer to it (or
a 
reference).

This is what your first function GetNameData is doing, although it is 
changing faceName to point to an array of pointers.

I.E.

char** Names;
( Names wants to point to an array of pointers).
int Count;
Count = GetNameData( &Names );

The variable Names is actually changed since a pointer (the address) of 
Names was passed in.

This is not always the case for a ** though, an array of pointers is 
sometimes set up this way, as we see for names.  Since we want to change 
names in the function an additional level of indirection is required, a 
pointer to a char** or char***.

In C++ we would make the call

int GetNameData(char**& faceName)

Or a reference to a char**.

Now it's possible that we would want to pass our pointer to our array of 
pointers to another function where it would be

DisplayNames( char** Names, int Count )

where we are not going to modify Names.  But we still need a pointer to a 
pointer because we still have an array of pointers.
-- 
Jim Langston
tazmaster@[EMAIL PROTECTED]

 




 4 Posts in Topic:
char** or char*** in function arguments?
Pat <pkelecy@[EMAIL PR  2008-05-03 12:26:02 
Re: char** or char*** in function arguments?
Ulrich Eckhardt <dooms  2008-05-03 19:21:02 
Re: char** or char*** in function arguments?
Pat <pkelecy@[EMAIL PR  2008-05-04 13:10:09 
Re: char** or char*** in function arguments?
"Jim Langston"   2008-05-04 15:06:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 16:11:58 CDT 2008.