L
L
LittleFatNinja2015-04-02 13:57:12
Programming
LittleFatNinja, 2015-04-02 13:57:12

C++. Why does adding +1 to an address increase the address by 8?

int *x =  new int(42);

cout << &x << endl;
cout << (&x) + 1 << endl;

output:
0x7fffa5c115c8
0x7fffa5c115d0

linux. 64

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Martyanov, 2015-04-02
@LittleFatNinja

Because the pointer starts pointing to the next element of the dimension for which the pointer was created. Make unsigned char* - it will increase by the size of char (1 most likely), unsigned long long* - by 8. void* most likely will not allow such a trick to turn at all (and will do it right).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question