+ 1

What will happen if we add some value in pointer which already have a address of a variable .

int v=60; int *p=&v; p+=2; cout<<p;

7th Sep 2018, 5:21 PM
Test 123
2 Antworten
+ 2
You will increment the address. This can be done for arrays for example. To access the next number in an array. Otherwise the pointer will point to unused memory with just some garbage value or even to a place where it should not point to at all and may cause a crash. So when incrementing pointers one has to be careful an know what you are doing.
7th Sep 2018, 5:28 PM
Matthias
Matthias - avatar
+ 2
Matthias thanks i just cleared my doubt while scrolling through q/a and found that this will just change the memory location of pointer p . thanks once again for explanation
7th Sep 2018, 5:32 PM
Test 123