简体   繁体   中英

Pass a 2D array to function

I have a 2D array

byte sensor_AND_1[2][NUM_OF_MAX_SENSORS] = { { 0 }, { 0 } }; 
byte sensor_AND_2[2][NUM_OF_MAX_SENSORS] = { { 0 }, { 0 } };

and a function where I need to pass the array to

if (is_valid_sensor_id_AND(sensor_AND_1,ID)) {  /*do something*/ }
else if (is_valid_sensor_id_AND(sensor_AND_2,ID)) {  /*do something*/ }

What is the correct declaration to pass the whole array to the function?

bool is_valid_sensor_id_AND(byte *arr, byte sensor_id)
    {
       for (size_t i = 0; i < NUM_OF_MAX_SENSORS; i++) {
          if (arr[0][i] == sensor_id) {
             arr[1][i] = 1;
             if (isset_counter(arr[1], NUM_OF_MAX_SENSORS)==isset_counter(arr[0], NUM_OF_MAX_SENSORS)) { triggered(sensor_id);  memset(arr[1], 0, NUM_OF_MAX_SENSORS); }
             return true;
          }
       }
       return false;
    }

我找到了如何将它传递给函数的答案: bool is_valid_sensor_id_AND(byte arr[][], byte sensor_id)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM