Does specifying size of array in parameter have any effect? For example.
void SetIDs(int IDs[22] );
versus
void SetIDs (int IDs[] );
Does it do nothing?
Does specifying size of array in parameter have any effect? For example.
void SetIDs(int IDs[22] );
versus
void SetIDs (int IDs[] );
Does it do nothing?
No, if you pass by value, an array type specifier in a parameter is always adjusted to a pointer.
void SetIDs (int IDs[22] );
void SetIDs (int IDs[] );
void SetIDs (int *IDs );
all produce the same code. Even sizeof IDs
inside SetIDs will only return the size of a pointer as if IDs was declared as int *IDs
.
The array size becomes relevant when you pass by reference or have a multidimensional array:
void SetIDs (int (&IDs)[22] );
This SetIDs will only accept (references to) arrays of int with size 22.
void SetIDs (int IDs[22][42] );
// equivalent to
void SetIDs (int (*IDs)[42]);
This SetIDs will accept pointers to (or an array of) an array of int with size 42.