malloc 返回值的类型是 void *
2024-10-19 02:19:07
malloc 返回值的类型是 void *,所以在调用 malloc 时要显式地进行类型转换,将 void * 转换成所需要的指针类型。
#include <iostream> using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//定义名为max_value的函数模板
template <class T> T max_value (T a,T b)
{
return ((a> b)? a: b);
} //在main()函数中测试max_value函数模板 int main(int argc, char** argv) {
//double类型数据使用max_value模板函数
double x = 1.2, y = 2.1;
cout<<"x="<<x<<"\t";
cout<<"y="<<y<<endl;
double result=max_value(x,y);
cout<<"max_value(x,y)="<<result<<endl;
cout<<"max_value(2*3.0,2+3.0)="<<max_value(*3.0,+3.0)<<endl;
cout<<"------------------"<<endl; //int类型数据使用max_value模板函数
int n= , m= ;
cout<<"n="<<n<<"\t";
cout<<"m="<<m<<endl;
cout<<"max_value(n,m)="<<max_value(n,m)<<endl;
cout<<"------------------"<<endl; //char类型数据使用max_value模板函数
char ch1='A',ch2='a';
cout<<"ch1="<<ch1<<"\t";
cout<<"ch2="<<ch2<<endl;
cout<<"max_value(ch1,ch2)="<<max_value(ch1,ch2)<<endl;
cout<<"------------------"<<endl; //字符串数据使用max_value模板函数
char str1[]="abc",str2[]="ABC",*p;
p=max_value(str1,str2);
cout<<"max_value("<<str1<<","<<str2<<")="<<p<<endl;
return ;
}
最新文章
- nginx File not found
- 通过jxl 读取excel 文件中的日期,并计算时间间隔
- uva oj 567 - Risk(Floyd算法)
- 【processing】小代码
- jenkins+gerrit
- Redis监控方案
- Markdown语法备忘
- Android 更好的Activity生命周期回调
- CustomSummaryCalculate 用法
- SpringMVC框架(一)
- 一位有着工匠精神的博主写的关于IEnumerable接口的详细解析
- 机器学习中的K-means算法的python实现
- 物料REVISION控制
- [Error]Can&#39;t install RMagick 2.13.4. You must have ImageMagick 6.4.9 or later.
- luogu P2617 Dynamic Rankings &;&; bzoj 1901 (带修改区间第k大)
- 【mysql】 mysql忘记密码
- php 图形用户界面GUI 开发
- paired-end reads的拼接
- vscode下调试caffe源码
- Android Fragment(三)ListFragment简单介绍以及Fragment之间通信
热门文章
- 完整的JavaScript版的信用卡校验代码
- Ubuntu14.04怎样使用root登录
- Zmodem transfer canceled by remote side问题的解决办法!
- 虚析构函数? vptr? 指针偏移?多态数组? delete 基类指针 内存泄漏?崩溃?
- OCR 识别原理
- nginx Beginner’s Guide
- unity, 不要change Default sharedMaterial
- Spring Cloud(七):使用SVN存储分布式配置中心文件和实现refresh
- Python目录常用操作
- atitit.Atitit. Gui控件and面板-----服务端控件 java struts的实现最佳实践