0

string lenght

how the string length of "chh" (strlen(chh)) is 10, if I don't put null at the end #include <bits/stdc++.h> using namespace std; int main() { char ch[]="aruna"; char chh[]={'a','r','u','n','a'}; cout <<"strlen(ch) "<<strlen(ch)<<'\t'<<" sizeof(ch)= "<< sizeof(ch) << endl; cout <<"strlen(chh) "<<strlen(chh)<<'\t'<<" sizeof(chh)= "<< sizeof(chh) << endl; return 0; }

23rd Mar 2018, 8:35 PM
Govindaraju C
Govindaraju C - avatar
3 odpowiedzi
+ 1
All strings ends by "\0", so u can: string c = "smth"; int len = 0; int i = 0; while (c[i] != "\0") { len++; I++; }
23rd Mar 2018, 8:40 PM
Maksym Debil
Maksym Debil - avatar
0
in chh I didn't put null, so iam getting strlen as 10 , how it is 10
24th Mar 2018, 8:58 AM
Govindaraju C
Govindaraju C - avatar
0
in chh I didn't put null, so iam getting strlen as 10 , how it is 10
24th Mar 2018, 9:03 AM
Govindaraju C
Govindaraju C - avatar