News for hackers. Stuff that matters.
Re:C Strings and my slow descent to madness by unwind on Thursday April 06, 2023 @12:52PM (#35471093)
This is almost a cliche among many C language lawyers and/or Stack Overflow answer-rich people and I know you mean well, but: arrays are not pointers.

In some contexts, the name of an array decays to a pointer to its first element. That is a better way of putting it, and it's a (much) weaker statement.

Edit: if they were the same, this code:

    int foo[] = {1, 2, 3};
    int *bar = foo;
    printf("%zu and %zu\n", sizeof foo, sizeof bar);
Would print the same valde twice, but it doesn't. On Ideone [1] I got 12 and 8.

[1]: https://ideone.com/CP7WTu

Re:C Strings and my slow descent to madness by int_19h on Thursday April 06, 2023 @03:52PM (#35473497)
This also makes a big difference once we start talking about pointers to arrays.

    int a[] = {1, 2, 3}
    int (*p)[3] = &a; // ok
    int *q = a; // not ok
Re:C Strings and my slow descent to madness by strkitten on Thursday April 06, 2023 @05:03PM (#35474405)
Nothing wrong with your third line. Did you mean something else?
Re:C Strings and my slow descent to madness by int_19h on Thursday April 06, 2023 @05:20PM (#35474635)
I forgot the &; comment updated now, and I added another example.
Re:C Strings and my slow descent to madness by strkitten on Thursday April 06, 2023 @05:27PM (#35474732)
Got it, thanks!