Pointer position reset

I have a pointer pointing to an array, and incremented each time I read the data. Each information has a different length, so I use strlen to jump the pointer. How to return a reset pointer back to its starting address ?! Thank you for your help.

+6
source share
2 answers

Save the original value in another pointer, then put it back.

char* original; char* current; current = wherePointerShouldPointAtStart(); original = current; while( someCondition() ) { usePointer( &current ); } current = original; 
+11
source

I think it is best to make a copy of the pointer, then whenever you need to reference the first element, you just use a new copy. Example:

 int *array = ..; int *beginning = array; 

If you need to reference the first element or even copy the source address to the source pointer, you simply use the start pointer.

+3
source

Source: https://habr.com/ru/post/889672/


All Articles