+ 5
C++ question with pointers
//Please someone can give me a logical explanation why this code gives -1 as result?? // and what is the value of t, p1 and p2...??; it seems an ambiguous problem int t[4]={8,4,2,1}; int *p1 = t+2, *p2 =p1-1; p1++; cout<<*p1-t[p1-p2];
3 Respuestas
+ 4
thanks for the answers it clears me up more
+ 2
When you write p1++ you are moving the pointer in memory not changing its value. Then anything can happen.
You probably want
(*p1) ++
If you want to know about moving pointers google Pointer Arithmetic