-4

Are these declarations different or do the produce the same result?

char * const *argv;

and

const char **argv;

Is there a difference or are both pointer to a pointer?

The background is that I was writing a C commandline shell and used this struct for a command:

struct command
{
    char * const *argv;
};

The above struct was used to call exec. Now when I looked at another question then the struct was different:

Connecting n commands with pipes in a shell?

In that question the struct to achieve the same is different.

Community
  • 1
  • 1
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424

1 Answers1

7

They are totally different:

char *const *argv; declares "a pointer to const pointer to char";

const char **argv; declares "a pointer to pointer to const char";

Also, char **const argv; declares "a const pointer to pointer to char".

To understand these declarations, try reading them "inside out": http://c-faq.com/decl/cdecl1.html

nalzok
  • 14,965
  • 21
  • 72
  • 139
  • 1
    It could be that the Answer is based on a mistyping. I think he meant `const char *argv;`. One less star :) – Michi Apr 11 '16 at 10:02