字串交換 (Swap String)

字串交換 (Swap String)

字串交換 實作教學與筆記。

說明

使用指標的指標(多重指標)來實現。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>

void swap(char** str1_ptr, char** str2_ptr) {
char *temp = *str1_ptr;
*str1_ptr = *str2_ptr;
*str2_ptr = temp;
}

void main() {
char* str1 = "Hello";
char* str2 = "World";
swap(&str1, &str2);
printf("str1 is %s, str2 is %s", str1, str2);
}
Author

Meow Lucian

Posted on

2019-07-17

Updated on

2022-07-04

Licensed under

Comments