pointer incrementation and assignment

后端 未结 2 1235
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 23:39

In the following two lines in C:

int* a = (int *)calloc(automata_size, sizeof(int));

int* b = (a++);

I found that a and b share the same addre

2条回答
  •  猫巷女王i
    2021-01-22 00:26

    So my advice is google post-increment and pre-increment. Pre-increment (++a) is:

    b = ++a;
    

    and is the same as:

    a = a + 1;
    b = a;
    

    Where as post-increment:

    b = a++;
    

    is the same as

    b = a;
    a = a + 1;
    

    this applies to pointers as well as integers.

提交回复
热议问题