使用指針實現數據交換

#include <stdio.h>

int changeFun(int *a, int *b);

int main(void){
    int a, b;
    int *ptr1 = &a;
    int *ptr2 = &b;
    puts("Enter two integer:");
    scanf("%d %d", &a, &b);
    printf("Before for change, the value is: %d %d.\n", a, b);
    changeFun(ptr1, ptr2);
    printf("After change, the value is: %d %d.\n", a, b);
    return (0);
} 

int changeFun(int *a, int *b){
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}
相關文章
相關標籤/搜索