+ 1

How to get length of int array in c++?

Int a[10] = {1,2,3,4}; In this case i have to find length is 4 not size

7th Oct 2019, 5:01 PM
Gaurav Rawat
Gaurav Rawat - avatar
4 ответов
+ 4
It's a C-style raw array. They don't come with a length, they're basically just a place in memory. Usually, for convenience, you keep an extra size variable around to control that array. Btw, the length of that array will always be 10, even if you only fill it up with 4 numbers - the remaining six will be set to zero.
7th Oct 2019, 5:12 PM
HonFu
HonFu - avatar
+ 3
Idk a lot about c++, but isn't it sizeof(a[0])?
7th Oct 2019, 5:13 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 1
By using string.h header file and strlen function
8th Oct 2019, 3:36 PM
Shoeb Rahman Jisan
Shoeb Rahman Jisan - avatar