-1

I have a function that receives a pointer to a char: void func(char *str)

I'm doing some checks on that array inside the function, but I want the actual address that the pointer is pointing to, will change outside the function (e.g. to str++).

I know that every change I do on str is actually done on the copy of the variable that function is creating. How can I solve this (I do not want to return it from the function, but to change the variable).

I read that it can be done with a pointer to a pointer, but I had a hard time understanding how this works exactly. Would love to have an explanation about this.

SagiBP
  • 1

1 Answers1

1

Pass the pointer by reference

void func(char **str);

In C passing by reference means passing an object indirectly through a pointer to it. Dereferencing the pointer you will get a direct access to the object pointed to by the pointer.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335