Char Pointer Argument/Parameter

Discussion in 'C++' started by Mike Copeland, Jul 12, 2008.

  1. 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
    Mike Copeland, Jul 12, 2008
    #1
    1. Advertising

  2. Mike Copeland

    Jim Langston Guest

    "Mike Copeland" <> wrote in message
    news:...
    > 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.
    Jim Langston, Jul 12, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alfonso Morra
    Replies:
    3
    Views:
    1,755
    Christopher Benson-Manica
    Aug 12, 2005
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,010
    Ian Collins
    May 9, 2006
  3. AikidoGuy
    Replies:
    11
    Views:
    544
    Seebs
    Nov 21, 2011
  4. Ryan Dupuis
    Replies:
    8
    Views:
    1,214
    Eric Sosman
    Oct 2, 2013
  5. Xavier Roche
    Replies:
    34
    Views:
    154
    Malcolm McLean
    May 13, 2014
Loading...

Share This Page