Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2019 04:25
What would you like to do?
void exchange(int*, int*);//宣告副程式,名字叫exchange
int main() {
int a, b;//宣告兩個整數
scanf("%d %d", &a, &b);//讓使用者輸入兩個數字
printf("a:%d b:%d\n", a, b);//列印出變數
exchange(&a, &b);//呼叫副程式,並且傳入a,b兩個整數的記憶體位址
printf("a:%d b:%d\n", a, b);//列印出變數
return 0;//跳出
void exchange(int* a, int* b) {
int ch;//宣告整數
ch = *a;//ch=a的記憶體位址
*a = *b;//a=b的記憶體位址
*b = ch;//b=ch的記憶體位址(原本a的記憶體位址)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment