what is pointer past the end of an object means?

后端 未结 3 935
野趣味
野趣味 2021-02-04 20:24

In C++ Primer, Chapter 2, \"Variables and Basic Types\", it says:

it is possible for a pointer to an object and a pointer one past the end of a different

3条回答
  •  终归单人心
    2021-02-04 20:45

    "one past" means "+1 operation on the pointer". The following code generates:

    0x7ffffcf6a848
    0x7ffffcf6a84c
    0x7ffffcf6a84c
    

    As you can see, the address of "one past a", i.e., &a + 1 is the same as &b.

        int a = 2; 
        int b = 3;
        cout<< &a << endl << &a + 1 << endl << &b <

提交回复
热议问题