不能把字符串"HELLO!"赋给数组b的语句是()
正确答案: B 你的答案: B (正确)
char b[10]={'H','E','L','L','O','!','\0'};
char b[10];b="HELLO!";
char b[10];strcpy(b,"HELLO!");
char b[10]="HELLO!";
B 选项是错误的,连编译都不会通过,因为数组名属于常性指针,现在要改变这个常性指针的指向,这是不会编译通过的,再说B 选项的本意是将Hello 拷贝到b指向的空间中,但实际却是将b指向了在常量区的Hellow 字符串(虽然编译不会通过)。
int GetStrRealLength(WCHAR *pwszWater)
{
int nLen = 0;
// 计算用户输入的字符串长度
WCHAR *strTemContent = pwszWater;
// 字符打印的数目每个英文+1 每个中文+2
int nLength = 0;
for(int nCirCtr = 0; nCirCtr < wcslen(strTemContent); ++nCirCtr)
{
if(0 < (*(strTemContent + nCirCtr)) && (*(strTemContent + nCirCtr)) < 256)
{
nLength += 1;
}
else
{
nLength += 2;
}
}
return nLength;
}