C/C++默认浮点型

Posted hu983

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C/C++默认浮点型相关的知识,希望对你有一定的参考价值。

代码:

 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默认为双精度浮点类型。

 

以上是关于C/C++默认浮点型的主要内容,如果未能解决你的问题,请参考以下文章