How to know the length of the array?
sizeof(ch)
does not fit because when it goes space, then this ends up
How to know the length of the array?
sizeof(ch)
does not fit because when it goes space, then this ends up
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
If the length of the array is in the form of a string, then:
#include <string.h> char charArr[] = "string"; strlen(charArr); // 6, размер самой строки strlen(charArr) + 1; // 7, размер массива с символом окончания строки
UPD:
If the length of the array is in the form int array []:
return sizeof(array)/sizeof(array);
If this array is dynamic , and there is no end-of-array criterion , then the answer is no way.
And what have the pros? If you need to work with strings, then std::string::length
to help. If with arrays, then std::vector
Source: https://ru.stackoverflow.com/questions/509515/
All Articles
sizeof
does not take into account the value of the variable It relies only on type . Describe the problem more specifically. - αλεχολυτ 8:43 pmstrlen
. - αλεχολυτ