*(a++) is giving error but not *(a+1)?? where a is array name?

前端 未结 3 1772
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 10:51

In following code:

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


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 11:02

    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;
    

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

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

提交回复
热议问题