c_cpp C - 指针作为参数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp C - 指针作为参数相关的知识,希望对你有一定的参考价值。

#include <stdio.h>

void swap(int *a, int *b){
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main(int argc, char *argv[]){
    int num1 = 5;
    int num2 = 10;
    printf("before swap: %d, %d\n", num1, num2);
    swap(&num1, &num2);
    printf("after swap: %d, %d\n",num1, num2);
    return 0;
}

以上是关于c_cpp C - 指针作为参数的主要内容,如果未能解决你的问题,请参考以下文章