指针作为函数参数
2016-02-25 10:26
218 查看
演示结果1:
![](http://images2015.cnblogs.com/blog/756783/201602/756783-20160225102316255-1583321180.png)
演示结果2:
![](http://images2015.cnblogs.com/blog/756783/201602/756783-20160225102332396-186275022.png)
示例代码:
![](http://images2015.cnblogs.com/blog/756783/201602/756783-20160225102316255-1583321180.png)
演示结果2:
![](http://images2015.cnblogs.com/blog/756783/201602/756783-20160225102332396-186275022.png)
示例代码:
#include <iostream> void swap(int *,int *); void swap1(int *,int *); void function1(void); void displayIntArray(int *,int); void bubbleSort(int *,int); void function2(void); int main(int argc, char** argv) { //function1(); function2(); return 0; } /** 演示排序 */ void function2(void){ int array[10]={9,1,2,5,6,3,4,8,7,10}; printf("原来的数组: "); displayIntArray(array,10); bubbleSort(array,10); printf("排序后数组: "); displayIntArray(array,10); } /** 冒泡排序 */ void bubbleSort(int *array,int arrayLength){ for(int i = 0;i<arrayLength;i++){ for(int j = 1;j<arrayLength-i;j++){ if(array[j]<array[j-1]){ swap1(&array[j],&array[j-1]); } } } } /** 展示数组 */ void displayIntArray(int *a,int arrayLength){ for(int i = 0;i<arrayLength;i++){ printf("%d ",a[i]); /* 五个数字 换一行 if((i+1)%5==0){ printf("\n"); } */ } printf("\n"); } /** 演示换位 */ void function1(void){ int a = 0xffffffff; int b = 0xfffffffe; printf("a = %d,b = %d\n",a,b); swap1(&a,&b); printf("a = %d,b = %d\n",a,b); int c = 0x7fffffff; int d = 0x00000001; printf("c = %d,d = %d\n",c,d); swap1(&c,&d); printf("c = %d,d = %d\n",c,d); } /** 交换算法1 */ void swap(int *a,int *b){ int temp = *a; *a = *b; *b = temp; } /** 交换算法2 */ void swap1(int *a,int *b){//两数之和大于0xffffffff 应该是也可以的。 *a = *a + *b;//10 9 *b = *a - *b;//10 1 *a = *a - *b; }
相关文章推荐
- 域名
- 2016年1月全球搜索引擎份额:百度被蚕食 跌至8.3%
- jquery插件jquery.LightBox.js实现点击放大图片并左右点击切换效果(附demo源码下载)
- 对象序列化分析(一)
- 【.Net码农】WinForm如何调用Web Service
- HTTPS协议说明
- 《浪潮之巅》笔记
- 实时渲染
- 一站式学习Wireshark(七):Statistics统计工具功能详解与应用
- maven冲突解决
- 自定义loading 以及动画loading
- android 自定义键盘 光标只在前面无法变动
- 自己写的日志框架--linkinLog4j--框架可配置+提性能
- Java基础:Day01笔记内容 (概述、JDK的下载及安装)
- java.nio.ByteBuffer用法小结
- select用法详解
- 23种设计模式(11):装饰者模式
- 使用maven开发spring项目报ClassNotFoundException异常
- 自己写的日志框架--linkinLog4j--框架可配置+提性能
- 【设计模式】状态模式