+ 1

how can i calculate length of array in c++

is there any function like in javascript we have array.length

31st Jan 2022, 4:09 AM
Vishal
Vishal - avatar
3 Answers
+ 5
In c++ I think there is only for strings, strlen() (including the corresponding library) If you want the length of an array you can do the following: sizeof(arr) / sizeof(arr[0]) There also seems to be a size function according to this code https://code.sololearn.com/cbtIgot3vYe3/?ref=app
31st Jan 2022, 4:18 AM
CGM
CGM - avatar
+ 5
If you're using the "array" class from the library "array", then you can use the "size" method to get it's length. Here's a sample code https://code.sololearn.com/cKFk9AI1LLFF/?ref=app
31st Jan 2022, 5:10 AM
Rishi
Rishi - avatar