I would like to loop through the array in this way.
for (int i=0; i < 10; i++)
{ Serial.println(sizeof(categorieArray[i]) / sizeof(int));
}
I assume that you are trying to print out the sizes of the respective arrays
categorie1,
categorie2, etc.
After understanding and fixing the part about what kind of pointer you are dealing with (so that it will compile without errors), the bottom line is that what you are trying to do here simply won't (can't, never has, never will) work. Not in C or C++. (But: See Footnote.)
Here's why:
For values of i = 0, 1, ... , 9,
categorieArray is a pointer.
The size of a pointer is fixed by the compiler implementer. The size of the pointer has nothing to do with the size of the array. Period. Full stop.
Regards,
Dave
Footnote:To perform something similar to what I think you want, you can do something like the following:
1. Define a struct that has an integer variable holding the size of an array and a pointer to int, which will point to an array.
2. Declare an array of those structs and initialize each struct member with the size of an array and a pointer:
struct Foo
{
int siz;
int * array;
};
int categorie1[] = {1};
int categorie2[] = {1, 2};
int categorie3[] = {3, 4, 5};
int categorie4[] = {4, 8, 3, 11};
int categorie5[] = {2, 4, 8, 3, 15 , 11, 12, 13};
int categorie6[] = {1, 2, 8, 12, 6};
int categorie7[] = {20, 1, 15};
int categorie8[] = {2, 4, 8};
int categorie9[] = {2, 6};
int categorie10[] = {2};
Foo foo[10] = {
{sizeof(categorie1)/sizeof(int), categorie1},
{sizeof(categorie2)/sizeof(int), categorie2},
{sizeof(categorie3)/sizeof(int), categorie3},
{sizeof(categorie4)/sizeof(int), categorie4},
{sizeof(categorie5)/sizeof(int), categorie5},
{sizeof(categorie6)/sizeof(int), categorie6},
{sizeof(categorie7)/sizeof(int), categorie7},
{sizeof(categorie8)/sizeof(int), categorie8},
{sizeof(categorie9)/sizeof(int), categorie9},
{sizeof(categorie10)/sizeof(int), categorie10},
};
void setup()
{
Serial.begin(9600);
for (int i = 0; i < 10; i++) {
Serial.print("Number of elements in the array of foo[");
Serial.print(i); Serial.print("] = ");
Serial.println(foo[i].siz);
}
}
void loop()
{
}
Output:
Number of elements in the array of foo[0] = 1
Number of elements in the array of foo[1] = 2
Number of elements in the array of foo[2] = 3
Number of elements in the array of foo[3] = 4
Number of elements in the array of foo[4] = 8
Number of elements in the array of foo[5] = 5
Number of elements in the array of foo[6] = 3
Number of elements in the array of foo[7] = 3
Number of elements in the array of foo[8] = 2
Number of elements in the array of foo[9] = 1