Help with pointer & array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • unclefester
    New Member
    • Mar 2008
    • 12

    Help with pointer & array

    I'm confused on how to interpret the following statement:

    Code:
    char * varName[];
    Is it a pointer to a char array or an array of char pointers? Advanced thanks.
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by unclefester
    I'm confused on how to interpret the following statement:

    Code:
    char * varName[];
    Is it a pointer to a char array or an array of char pointers? Advanced thanks.
    This is array of pointer.
    when you declare something like:
    char (*p)[5];
    then 'p' is called as pointer to array.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Originally posted by unclefester
      char * varName[];
      This won't compile. You cannot create an array without specifying the number of elements. Do not confuse the above with this:
      [code=c]
      char * varName[] = {"Hello", "world"};
      [/code]

      Here varName is an array of 2 char*. The compiler gets the number of elements from the the initialization syntax.

      Maybe you could read http://www.thescripts.com/forum/thread772412.html.

      Comment

      Working...