sizeof’ on array function parameter ‘arr’ will return size of ‘int*’ [-Wsizeof-array-argument]

The warning message "sizeof' on array function parameter 'arr' will return size of 'int'" is indicating that the usage of the sizeof operator on the array function parameter 'arr' will return the size of 'int' (pointer to int) instead of the expected size of the array itself.

Let's break down the explanation step by step:

  1. The sizeof operator is used to determine the size, in bytes, of a type or an expression. It can be used with different types, such as int, char, or user-defined types.

  2. In this case, the sizeof operator is applied to the function parameter 'arr'. The function parameter 'arr' is declared as an array, but in C++, when an array is passed as a function parameter, it decays into a pointer to its first element.

  3. So, when the sizeof operator is used on the function parameter 'arr', it actually returns the size of the pointer to int (int*), not the size of the original array.

  4. The warning message "[...] sizeof' on array function parameter 'arr' will return size of 'int*'" is informing you about this behavior and suggesting that you might not be getting the expected size of the array when using sizeof on the function parameter.

To get the size of the array itself, you can either pass the array size as a separate parameter to the function or use a template function that deduces the array size. Alternatively, you can use some other mechanism to track the size of the array, such as using a sentinel value or storing the size in a separate variable.

I hope this explanation clarifies the meaning of the warning message. Let me know if you have any further questions!