0
Returning the leght of an array in c / c++
I need to return the number of variables in an array. I tried sizeof but it returns the number of bytes in a variable. Can you help me?
3 Respostas
+ 2
This code has a small macro called arrSize at the beginning that will determine the size of the array at compile time :)
https://code.sololearn.com/cQ0IA7I7781G/?ref=app
+ 3
I Need exactely what Aaron said. Thank you
+ 2
By "Returning the length of an array" you mean you pass the array into a function as argument and get its element count?
FYI once you pass an array as function argument use of sizeof(array) / sizeof(array[0]) can no longer give you a valid result. Array size is known only where the array was declared and/or initialized.
Please share your code link in Description section to prevent misunderstanding 👍