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; }
3 Respostas
+ 1
All strings ends by "\0", so u can:
string c = "smth";
int len = 0;
int i = 0;
while (c[i] != "\0") {
len++;
I++;
}
0
in chh I didn't put null, so iam getting strlen as 10 , how it is 10
0
in chh I didn't put null, so iam getting strlen as 10 , how it is 10