How pointer assignment and increment work in the following example

I am learning pointers to C. I'm a little confused about how the program below works

int main() { int x=30, *y, *z; y=&x; z=y; *y++=*z++; x++; printf("x=%d, y=%p, z=%p\n", x, y, z); return 0; } 

output

 x=31, y=0x7ffd6c3e1e70, z=0x7ffd6c3e1e70 

y and z indicate the next integer address of the variable x . I can’t understand how this line works.

 *y++=*z++; 

Can someone please explain to me how this single line is understood by C?

+5
source share
1 answer

*y++=*z++; means

 *y = *z; y += 1*(sizeof(int)); //because int pointers are incremented by 4bytes each time z += 1*(sizeof(int)); //because int pointers are incremented by 4bytes each time 

The exact value is not affected, the pointers are incremented by one.

+4
source

Source: https://habr.com/ru/post/1260699/


All Articles