In C ++, how does the expression "* pointer ++" work?
Post-increment ( ++) has a higher priority than dereferencing ( *). This means that it ++binds to pointer, not *pointer.
See C FAQ 4.3 and the links in it.
Well, everyone explained the parameter binding.
But no one mentioned what this means.
int date[1,2,3,4,5];
int* pointer = data;
std::cout << *pointer++ << std::endl;
std::cout << *pointer << std::endl;
, ++ , , , *. , :
std::cout << *(pointer++) << std::endl;
std::cout << *pointer << std::endl;
++ - . , , *. , :
std::cout << *pointer << std::endl;
pointer++;
std::cout << *pointer << std::endl;
, , , . 1\n2\n not 2\n\3\n.
*pointer++means *(pointer++).
ie, it increments a pointer, not a pointee.
one way to remember is to read the original K & R "C Programming Language", which uses an example strcpy.
since I remember the priority.
and as it increments the pointer, your second dereference has Undefined Behavior.
greetings and hth.,