I recently realized that C ++ allows pointers to arrays of unknown sizes, like
int (*p)[];
The declaration above is not equivalent to int* p; . In fact, trying to use p to specify a fixed-size array results in a compile-time error, for example
int data[42]; p = data; // error, cannot convert int [42] to int (*) []
or
int* data; p = data; // error, cannot convert int * to int (*) []
My question is when and why should we use such a pointer to an array of unknown size? Are there any good reasons for this, and just use int* instead?
EDIT
Such objects are not allowed as function parameters, see Pointer to an array of undetermined size "(* p) []" is illegal in C ++, but legal in C , but can nevertheless be declared in the program.
source share