delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/09/09:48:39

From: eyal DOT ben-david AT aks DOT com
To: gmeyers AT logan DOT net
cc: djgpp AT delorie DOT com
Message-ID: <422564B1.004E9870.00@aks.com>
Date: Mon, 9 Jun 1997 16:47:17 +0200
Subject: Re: char **argv vs. char *argv[]
Mime-Version: 1.0



>>  I've seen char **argv and char *argv[] and am curious which is correct
Or
>> are either correct?
> They are both the same thing.  The array syntax is interchangable with
> pointer
> arithmetic.  Or at least should be if the compiler in question follows
the
> language at all.

Not exact.  The are both the same thing only when used as parameters
to functions (like in main).

char*   argv1[]  (not as a parameter)      is an array of pointer
variables.
char** argv2    (always)  is a pointer (variable holding the address of)  a
pointer-to-char.

for example :

extern char* argv1[];    /* declares array of pointers. */
extern char **argv2;

argv1++;    // ERROR this is an array !!
argv2++;   // OK.

so there is difference.

Eyal.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019