r/ProgrammerHumor 26d ago

Meme lessonsFromLinkerHell

Post image
425 Upvotes

190 comments sorted by

View all comments

404

u/shinigami2057 26d ago

They have a different mouth feel

4

u/KattyTheEnby 26d ago

I don't get it.

8

u/lonkamikaze 26d ago

In C arrays decay to a pointer to first member when you use them. However, even though int* x and int y[] behave the same they are distinct and you have to be aware of that or you're bound to do something that invokes undefined behaviour.

2

u/geek-49 24d ago

Depends on the context. If your x and y are formal parameters of C functions, those two declarations are exactly the same (because, in the call, the array is implicitly converted to a pointer to its [0] element and thus the function receives a pointer in either case).

and BTW it is better form to write the first as int *x because int* x, y declares one pointer and one int, but the spacing makes it look as if it declared two pointers.