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?

24th Sep 2019, 7:47 AM
Franky
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
24th Sep 2019, 8:14 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 3
I Need exactely what Aaron said. Thank you
24th Sep 2019, 11:15 AM
Franky
+ 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 👍
24th Sep 2019, 10:34 AM
Ipang