- /*
- 说明:虽然发的一些C语言的代码可能有的人认为很简单,但是我觉得对大家
- 有的人来说应该还是很有用的,所以就贴上来了。
- */
- #include<stdio.h>
- void main()
- {
- void swap(int *a,int *b);/*函数说明*/
- int i,j,*p,*q;
- i=320;
- j=220;
- p=&i;/*p指向变量i的地址*/
- q=&j;/*q指向变量j的地址*/
- printf("\\n before calling value:i=%d j=%d",*p,*q);
- swap(&i,&j);/*调用函数*/
- printf("\\n after calling value:i=%d j=%d",*p,*q);
- system("pause");
- }
- void swap(int *a,int *b)/*指针变量作为形式参数,两个参数都是地址,,互相交换两个指针变量*/
- {
- int temp;/*临时变量*/
- temp=*a;/*指针变量a所指向的地址的内容值*/
- *a=*b;/*将b针变量的所指向的值赋给a指针变量所指向的地址的值*/
- *b=temp;/*将临时变量的值赋给指针变量b所指向的地址的内容值*/
- printf("\\n in the function :a=%d b=%d",*a,*b);
- }
- //该片段来自于http://www.codesnippet.cn/detail/040220132066.html
来源: http://www.codesnippet.cn/detail/040220132066.html