Skip to main content
added 470 characters in body
Source Link
interjay
  • 111k
  • 22
  • 278
  • 264

For byte-sized elements, you can use sizeof(data).

More generally, sizeof(data)/sizeof(data[0]) will give the number of elements.


Since this issue came up in your last question, I'll clarify that this can't be used when you pass an array to a function as a parameter:

void f(byte arr[]) { //This always prints the size of a pointer, regardless of number of elements. cout << sizeof(arr); } void g() { byte data[] = {0xc7, 0x05, 0x04, 0x11 ,0x45, 0x00, 0x00, 0x00, 0x00, 0x00}; cout << sizeof(data); //prints 10 } 

For byte-sized elements, you can use sizeof(data).

More generally, sizeof(data)/sizeof(data[0]) will give the number of elements.

For byte-sized elements, you can use sizeof(data).

More generally, sizeof(data)/sizeof(data[0]) will give the number of elements.


Since this issue came up in your last question, I'll clarify that this can't be used when you pass an array to a function as a parameter:

void f(byte arr[]) { //This always prints the size of a pointer, regardless of number of elements. cout << sizeof(arr); } void g() { byte data[] = {0xc7, 0x05, 0x04, 0x11 ,0x45, 0x00, 0x00, 0x00, 0x00, 0x00}; cout << sizeof(data); //prints 10 } 
Source Link
interjay
  • 111k
  • 22
  • 278
  • 264

For byte-sized elements, you can use sizeof(data).

More generally, sizeof(data)/sizeof(data[0]) will give the number of elements.