using namespace std; int main () { int value = 1, *pointer; pointer ...">

In C ++, how does the expression "* pointer ++" work?

#include <iostream>
using namespace std;

int main () {
    int value = 1, *pointer;
    pointer = &value;
    cout << *pointer++ << endl;
    cout << *pointer << endl;
}

Why ++doesn't the operator zoom in value?

+3
source share
6 answers

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.

+9
source

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.

+7

++ , *, *(pointer++) - , . , (*pointer)++.

+3

,

*(pointer++)

, , , .

+2
source

*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.,

+1
source

You increase the value of the pointer, not the value indicated by it.

0
source

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


All Articles