In C all arguments are passed by value, even pointers. That means if you pass a pointer to a function the pointer is copied, and the function will have a local copy that it can modify as it likes without affecting the original pointer.
Example:
#include <stdio.h>
void print_pointer_plus_one(const char *pointer)
{
++pointer; // Make pointer point to the next element
printf("In call: %s\n", pointer);
}
int main(void)
{
const char* hello = "hello";
printf("Before call: %s\n", hello);
print_pointer_plus_one(hello);
printf("After call: %s\n", hello);
}
The above program should print
Before call: hello
In call: ello
After call: hello
The function you call could modify the data that the pointer is pointing to, and this will affect the data itself and not the pointer. This can be used to emulate pass by reference:
#include <stdio.h>
void modify_data(char *pointer)
{
pointer[0] = 'M'; // Modify the data that pointer is pointing to
}
int main(void)
{
char hello[] = "hello";
printf("Before call: %s\n", hello);
modify_data(hello);
printf("After call: %s\n", hello);
}
This program will print
Before call: hello
After call: Mello