+ 1
Double vs float C/C++
Why does this code output 1 and not 2? #include <iostream> using namespace std; void f(float x){cout << 2;} void f(double x){cout << 1;} void f(int x){cout << 3;} int main() { f(1.0); return 0; }
3 Réponses
+ 3
Precision numbers default by double types.. so 1.0 is double type. So it calls f(double x){}.
Use 1.0f for float type function callings...
+ 2
Jayakrishna, ah ok, I didn’t know that, thank you!
+ 1
purpose of this q/a section, know about..
You're welcome..