*(A ++)是给错误,但不是*(A + 1)??其中a是数组名? [英] *(a++) is giving error but not *(a+1)?? where a is array name?

查看:238
本文介绍了*(A ++)是给错误,但不是*(A + 1)??其中a是数组名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下code:

void main()
{
    char a[]={1,5,3,4,5,6};
    printf("%d\n",*(a++)); //line gives error: wrong type argument to increment
    printf("%d\n",*(a+1));
}

之间有什么行4和第5行,我没有得到任何错误或线5警告的区别。

What is the difference between line 4 and line 5. I am not getting any error or warning with line 5.

推荐答案

A 是一个数组对象,而不是一个指针,所以你不能使用操作 A ++
对于数组对象。因为这相当于:

a is an array object and not a pointer so you could not use the operation a++ for an array object. because this is equivalent to :

a = a+ 1;

下面你分配给数组对象,它是不是在C不允许新值。

Here you are assigning to the array object a new value which is not allowed in C.

A + 1 返回一个指向该元素的 A 阵列1,它是允许

a + 1 return a pointer to the element 1 of your a array and it's allowed

这篇关于*(A ++)是给错误,但不是*(A + 1)??其中a是数组名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆