Sie sind auf Seite 1von 1

double pointers Consistent with how a pointer can be given so that a function can modify its con tents,

a double pointer can be given as a mechanism for a function to modify the pointer. Suppose I have a function that takes a string. That's your pointer. No w suppose the function wants the ability to change what string we were actually pointing to (not the same thing as modifying the string itself), it will need a double pointer. #include <stdio.h> #include <string.h> void swap(char **a, char **b) { char *temp = *a; *a = *b; *b = temp; } int main() { char *a = "World"; char *b = "Hello"; printf("%s %s\n", a, b); swap(&a, &b); printf("%s %s\n", a, b); return 0; }

Das könnte Ihnen auch gefallen