# Function parameters

Hello everybody , I want to create a function that returns an array parity by xor, my code doesn't work

``````boolean d[16] = {0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0};
boolean S;

void Xor(boolean *x, boolean T[]) {
Â  int i = 1;
Â  *x = T[0];
Â  for (i = 1; i < sizeof(T); i++) {
Â  Â  *x =Â  T[i] xor * x;
Â  }
}
void setup() {
Â  Serial.begin(9600);// put your setup code here, to run once:
}

void loop() {
Â  /* int i= 1;
Â  Â  S=d[0];
Â  Â  while(i<sizeof(d)){
Â  Â   S=S xor d[i];
Â  Â   i++;
Â  Â   }*/
Â  Xor(&S, d);
Â  Serial.print(S);
Â  delay(5000);
}
``````

I would write it this way:

``````boolean testArray[16] = {0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0};

boolean parity(boolean *array, size_t len) {
Â  boolean result = false;
Â  for (size_t idx = 0; idx < len; idx++) {
Â  Â  result ^= array[idx];
Â  }
Â  return result;
}

void setup() {
Â  Serial.begin(115200);
Â  boolean arrayParity = parity(testArray, sizeof(testArray));
Â  Serial.print(F("parity = "));
Â  Serial.println(arrayParity);
}
void loop() {}
``````
``````parity = 1
``````

Yes, it works thank you very much

honestly It's not easy for me to handele this part, I tried to creat another function like this

``````boolean Affect(boolean *d[],int *pX[]){
Â  boolean Xd[sizeof(pX)];
Â  for(int i=0; i<sizeof(pX);i++){
Â  Â  Xd[i]= d[*pX[i]];
Â  Â  }
Â  Â  return Xd;
Â  }
``````

but it gives me this error
cannot convert 'boolean ()[44] {aka bool ()[44]}' to 'boolean** {aka bool**}' for argument '1' to 'boolean Affect(boolean**, int**)'

medeloualidi:
honestly It's not easy for me to handele this part, I tried to creat another function like this

``````boolean Affect(boolean *d[],int *pX[]){
``````

boolean Xd[sizeof(pX)];
Â  for(int i=0; i<sizeof(pX);i++){
Â  Â  Xd[i]= d[*pX[i]];
Â  Â  }
Â  Â  return Xd;
Â  }

``````

but it gives me this error
cannot convert 'boolean (*)[44] {aka bool (*)[44]}' to 'boolean** {aka bool**}' for argument '1' to 'boolean Affect(boolean**, int**)'
``````

I'd look at what is being passed to the function. Compiler is complaining that it isn't what the function expects.

sizeof in that context will NOT tell you the length of the array. It will tell you how many bytes of memory the pointer to the array occupies. There is not way to determine the amount of memory allocated to an array. If your function needs the array length you must pass it as an argument.

All things, BTW, that can be easily determined by writing a few simple lines of code to TEST what your code is actually doing, as opposed to what you imagine it's doing...

Regards,
Ray L.