0

Is there a difference between defining:

void example(int usuario[]);

or

void example(int usuario[SIZE]);
kabanus
  • 24,623
  • 6
  • 41
  • 74
  • 1
    Check this answer https://stackoverflow.com/questions/1810083/c-pointers-pointing-to-an-array-of-fixed-size – Nasr Nov 17 '18 at 18:06

1 Answers1

3

In c, the array name when passed decays to a pointer. Using a sizeof in both your examples on usario will return the size of an int pointer, regardless of SIZE. So both examples are identical, and are the same as

void example (int *usario)

The [] syntax in this context is purely syntactic sugar. Functionally, a pointer will be what you are actually working with - the [] or [SIZE] are only useful for a future programmer to see you expect an array with length SIZE. This will not be enforced by the compiler at all.

On a modern compiler, you will get a warning if you do sizeof(usario) in the function - you can try it with both your examples.

kabanus
  • 24,623
  • 6
  • 41
  • 74