C语言之指针数组和数组指针
数组名只是一个地址,而指针是一个左值。
[liangjian@localhost ~]$ cat test27.c
#include <stdio.h>
int main()
{
char str[]="I Love FishC.com!";
int count=0;
char *target=str;
while (*target++ !='\0')
{
count++;
}
printf("该字符串的长度为%d个字符!\n",count);
return 0;
}
[liangjian@localhost ~]$ gcc test27.c &&./a.out
该字符串的长度为17个字符!
[liangjian@localhost ~]$
[liangjian@localhost ~]$ cat test27.c
#include <stdio.h>
int main()
{
char str[]="I Love FishC.com!";
int count=0;
// char *target=str;
while (*str++ !='\0')
{
count++;
}
printf("该字符串的长度为%d个字符!\n",count);
return 0;
}
[liangjian@localhost ~]$ gcc test27.c &&./a.out
test27.c: 在函数‘main’中:
test27.c:7:13: 错误:自增操作数必须是左值
while (*str++ !='\0')
[liangjian@localhost ~]$