0
点赞
收藏
分享

微信扫一扫

C语言之指针数组和数组指针

c一段旅程c 2022-03-22 阅读 212
c语言

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 ~]$ 
举报

相关推荐

0 条评论