AWOL:
Can't disagree in general, but try overloading "printArray" with an "int" array method.
The function looks about the same:
// The "siz" parameter is the number of elements in the array
void printArray(int *x, int siz)
{
for (int i = 0; i < siz; i++) {
Serial.print(" ");
Serial.print(x[i]);
}
}
The calling function must determine the number of elements in the array, and your advice is one way for a function that can see the array can determine the size.
However...
It's not necessary to use sizeof() at all:
void loop()
{
const int bSize = 3;
// A "local" array of ints.
int b[bSize] = {6, 7, 8}; // Re-initialized every time through the loop
// When you use the name of an array as an argument in a function call
// it is passing a pointer whose value is the address of the
// first element of the array.
Serial.print("Calling printArray(b, bSize) :");
printArray(b, bSize);
Serial.println();
.
.
.
Of course I could have used sizeof(b)/sizeof(b[0]) to let the compiler calculate the number of elements in the array at compile time, but I almost always use the method that I showed here: Specify the number of elements in the array by using a constant in the definition. Then use that constant wherever you need it. (Note that there is no code size or run time overhead for using a constant like this, just as there is no code size or run time overhead for using sizeof() in an expression.)
Since the Original Poster asked about sizeof(), I was trying to respond to his question and I showed that sizeof() gave the number of bytes in the byte array, provided that the program can "see" the array at that point. It might have been more instructive to go into a more general example (using an array of ints or floats or some such thing) that could use your advice to determine the number of elements, but my point is something that you already knew but the Original Poster apparently did not.
Namely that a function that works on an array can not know the how many elements are in the array unless you tell it. I gave a general method of telling it: Define the function to have a parameter that tells it the number of elements in the array.
Regards,
Dave
Footnote:
The thing that we all want to avoid is "hard-coding" the array size at multiple points in the program:
void loop()
{
// A "local" array of ints.
int b[3] = {6, 7, 8}; // Re-initialized every time through the loop
// When you use the name of an array as an argument in a function call
// it is passing a pointer whose value is the address of the
// first element of the array.
Serial.print("Calling printArray(b, 3) :"); // If you change the array size, don't forget to change this too!
printArray(b, 3);
Serial.println();
That just increases the probability of a "forgetful" error in case we want to modify the array to have more or fewer elements. By using the sizeof(b)/sizeof(b[0]) expression or by using the const stuff I showed, we don't have to remember to change the siz parameter every place we call the function.
I mean, I could have put all of this stuff in my original response, but...