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

前端 未结 3 1748
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  一整个雨季
    2021-01-12 11:28

    Okay seriously bad coding practices: However let's first address your issue:

    printf("%d\n",*(a++)); //this lines gives error: wrong type argument to increment
    

    can't be used because a is an implicit reference to the array;

    You CAN do this:

    char b[]={1,5,3,4,5,6};
    char *a = b;
    printf("%d\n",*(a++)); //this lines will not give errors any more
    

    and off you go...

    Also *(a++) is NOT the same as *(a+1) because ++ attempts to modify operand whereas + simply add one to constant a value.

提交回复
热议问题