0

int []x in a code block creates an array on the stack while int *x holds a pointer (or an array). As function parameters though, e.g.

int getElement(int x[], int index){ ... }

int getElement(int *x, int index){ ... }

int getElement(int x[78], int index){ ... }

where 78 is any arbitrary constant, all of these function definitions behave exactly the same way, even if I access an index higher than 78 directly by value or by a variable. Is there any difference between these?

Xceptional
  • 65
  • 7
  • The first and second are essentially the same. The third carries a dimension only useful for the typesystem, example context, `sizeof`. And BTW, C++ will not prevent you from going out of bounds... – WhiZTiM Dec 02 '17 at 18:27
  • No, C++ seems to gleefully chortle when you go out of bounds. I swear it mocks me. – user4581301 Dec 02 '17 at 18:28

0 Answers0