Pointer variable as a function parameter The function of the pointer type is to tell the address of one variable to another function
//在函数过程中通过指针实现交换两个变量的值 #include "stdafx.h" #include <stdio.h> int main(int argc, char* argv[])
{ void swap(int *p1,int *p2); int a,b; int *pointer_1,*pointer_2; printf("please enter a and b"); scanf("%d,%d",&a,&b); pointer_1=&a; pointer_2=&b; if(a<b) swap(pointer_1,pointer_2); printf("max=%d,min=%d\n",a,b); Output result return 0;
} void swap(int *p1,int *p2)// The point of the pointer, pointer as a parameter When the function is called, the value of the parameter variable is transferred to the parameter variable, which is the method of value transfer. {int temp; temp=*p1; *p1=*p2; Make *p1 and *p2 interchangeable *p2=temp;
}
|