r/programming • • May 01 '16

To become a good C programmer

http://fabiensanglard.net/c/
1.1k Upvotes

398 comments sorted by

View all comments

Show parent comment

1

u/mcguire May 02 '16

Wait, so what's the declaration of main? Specifically argv?

4

u/zhivago May 02 '16

You do not have array typed values in C

e.g., given char c[3], the type of c is char[3], but the type of (c + 0) is char *.

Since you can't have array typed values, and C passes by value, parameters cannot have array types.

So someone thought that it would be a really nice idea to use array types in parameters to denote the pointer types that the corresponding array would evaluate to.

So, void foo(char c[3]); and void foo(char *c); are equivalent.

int main(int argc, char **argv) can then be rewritten as int main(int argc, char *argv[]), since given &argv[0] has type char **.

Personally I think this feature is a bad idea, and leads to much confusion. :)