Go back to the beginning of the pointer?

I know you can take a pointer, for example:

someFunction(const char* &txt)
{
    txt++; //Increment the pointer
    txt--; //Decrement the pointer
}

how do i go back to the start of the pointer? (not taking into account my number of increments and decreasing this amount) I was thinking about something like:

txt = &(*txt[0]);

But this does not work (by assigning a pointer to its starting location).

Any help would be greatly appreciated.

Brett

+3
source share
4 answers

You can not. You must either keep the starting position:

const char *o = txt;
// do work
txt = o;

Or use the index:

size_t i = 0;
// instead of txt++ it i++
// and instead of *txt it txt[i]
i = 0;

Your attempt:

txt = &(*txt[0]);

, . -, txt[0] ( char), *, & ( , , char), () . :

const char *txt = 'a';

. , , , ,

txt = &txt[0];

, , , txt txt, , txt[0] - *(txt + 0) *txt. &*txt txt, :

txt = txt;

. . .

+9

"". , ( - ), , , "" .

, , ( ). .

+3

, , , , , , .

int a[10] = {0};
int *p = NULL;

p = a; // start of array
++p;   // p points to a + 1
++p;   // p points to a + 2, 
       // .. but there is no intrinsic information in 'p' where start of 'a' is.
0

The easiest way is to use a different value to keep the original index 0. I don’t think you can really go to the “first” if this does not look like an ordered data structure.

0
source

All Articles