I'm doing the excises on the book of 《C++ Primer》 5th, there is an excise on page 38,2.7
(c) 1024f
When I run it in my computer, just like below, GCC gave me an error:
error: invalid suffix "F" on integer constant
can someone help me to explain the reason?
#include<iostream>
using namespace std;
int main()
{
cout << 1024f << endl;
return 0;
}
1024f isn't a float value and also not a int for example
So it can't compile. What you want to do is 1024.f
In that way you explicitly say that the number 1024 has to be of type float.
int main() {
cout << 1024.f << endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With