Char Pointer Argument/Parameter

M

Mike Copeland

How do I distinguish a pointer to a character variable versus a
pointer to a C-type character string? For example,

void Funct1(char *str) // "str" is a character string variable
void Funct2(char *chr) // "chr" is a single character variable

In both cases, I wish to modify the parameter argument, but it seems
to me they are really different data types.
Also, is there any way to _override_ the declaration of a function
with these 2 distinctive data types? Please advise. TIA
 
J

Jim Langston

Mike Copeland said:
How do I distinguish a pointer to a character variable versus a
pointer to a C-type character string? For example,

void Funct1(char *str) // "str" is a character string variable
void Funct2(char *chr) // "chr" is a single character variable

In both cases, I wish to modify the parameter argument, but it seems
to me they are really different data types.
Also, is there any way to _override_ the declaration of a function
with these 2 distinctive data types? Please advise. TIA

They actually aren't different types that is. A pointer doesn't care if it
points to one object, or a number of objects. One thing you could do for
yourself to help self document it a little is:

void Func1( char str[] ) // "str" is a character string variable
void Func2( char* chr ) // "chr" is a single character variable

But it really doesn't make a difference. Although I've never seen the []
format used for a single character. You can still pass the address of a
single character to Func1 or Func2, or an array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top