-1

I'm new in c programming. I'm quite confused with the difference between:

int main (int argc, char **argv)

and

int main (int argc, char *argv[])

are they the same in C programming?

Lundin
  • 195,001
  • 40
  • 254
  • 396
user354227
  • 55
  • 2
  • That thread is not a duplicate, it is only concerned about the format of main, not the difference between `char**` and `char* []`, which is actually what this question is about. I will re-open this. – Lundin May 24 '16 at 11:45
  • @MohitJain That seems like a possible duplicate. However, that thread is some old one which is phrased to give subjective and opinion-based answers (it has numerous real crappy ones), so I'm not sure it is a good one to use. – Lundin May 24 '16 at 11:49
  • @Lundin Yes, but the intent of the questions is same. And the answer there essentially applies/fits to this question. – Mohit Jain May 24 '16 at 11:51
  • @MohitJain Such a crappy thread though... even the top answer is kind of bad, because he drags in all manner of non-related things like function pointers, in an answer that should be just a few paragraphs long at most. – Lundin May 24 '16 at 11:54
  • @Lundin Hmmm. In that case we need good answers on atleast one question and second question should be marked duplicate. Either edit and update existing answers there or mark the old one as duplicate of this or add some updated answers here. I feel like former is a good (simpler) idea. But with your experience with SO community possibly you can decide better. – Mohit Jain May 24 '16 at 11:58

1 Answers1

1

Yes they are the same, when part of a function parameter list.

The specifics are that char* argv[] actually declares an array of unknown size, where each item in the array is a pointer. But whenever an array declaration appears as part of a function parameter list, it gets silently replaced by a pointer to the first element.

The first element of an arrar of char* is of course of type char*, so therefore a pointer to the first element would be type char**.

Lundin
  • 195,001
  • 40
  • 254
  • 396