strlen特点,遇'\0'(空)结束。以下程序结果对你有帮助。
#include <stdio.h>
#include <string.h>
int main()
{
char x[] = "efgh";
char y[] = {'a', 'b', 'c', 'd'};
int len1 = strlen(x);
int len2 = strlen(y);
int i;
printf("%d %d\n",len1,len2);
for(i=0;i<9;i++)
printf("%p: %c\n",y+i,y);
return 0;
}
[\b]
cout<<y<<endl;试试看就知道了 #include <iostream>
#include <string.h>
using namespace std;
int main()
{
char x[] = "abcd";
char y[] = {'a', 'b', 'c', 'd','\0'};
int len1 = strlen(x);
int len2 = strlen(y);
cout<<len1<<" "<<len2<< y<< endl;
return 0;
}
页:
[1]