首页 > 技术文章 > C/C++默认浮点型

hu983 2016-05-28 17:11 原文

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 void test(int a){
 7     cout<<a<<endl;
 8 }
 9 void test(float a){
10     cout<<a<<endl;
11 }
12 
13 int main(){
14     
15     test(1);
16     test('c');
17     //test(0.5); //编译不通过,默认为double类型
18     test(0.5f);
19 
20     return 0;
21 }

输出:

1
99
0.5

 分析:

0.5默认为双精度浮点类型。

 

推荐阅读