使用void指针给函数传递不同的数据类型
2015-10-25 00:00
513 查看
#include <stdio.h> void half(void *pval, char type); int main(void){ int i = 20; long l = 100000; float f = 12.456; double d = 123.044444; printf("\n%d", i); printf("\n%ld", l); printf("\n%f", f); printf("\n%lf\n\n", d); half(&i, 'i'); half(&l, 'l'); half(&d, 'd'); half(&f, 'f'); printf("\n%d", i); printf("\n%ld", l); printf("\n%f", f); printf("\n%lf\n", d); return (0); } void half(void *pval, char type){ switch(type){ case 'i':{ *((int *)pval) /= 2; break; } case 'l':{ *((long *)pval) /=2; break; } case 'f':{ *((float *)pval) /=2; break; } case 'd':{ *((double *)pval) /=2; break; } } }
相关文章推荐
- 使用可变数目的参数列表
- 使用c语言标准库中的时间函数
- RabbitMQ如何应对消费出现异常的情况
- RabbitMQ如何应对Server出现异常以及server分发任务的负载均衡问题
- RabbitMq中的exchange是什么
- 编写不受魔术引号影响的php应用
- 面向对象类-类
- 正则表达式
- Mint17/Ubuntu14.04 samba文件服务器搭建
- 解决PhpStorm不能自动提示父类的方法的问题
- HTTP的请求类型GET,PUT,POST
- MyBatis整合Spring的实现(2)
- MyBatis整合Spring的实现(3)
- MyBatis整合Spring的实现(4)
- MyBatis整合Spring的实现(5)
- MyBatis整合Spring的实现(6)
- Swift引入Header.h文件
- OC17内存管理和自动引用计数
- JAVA动态代理的理解
- 创业的第五十七天