Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1024f invalid suffix "F" on integer constant

Tags:

c++

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;
}
like image 407
Liu Guangxuan Avatar asked Nov 01 '25 12:11

Liu Guangxuan


1 Answers

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;
}
like image 76
Bas Avatar answered Nov 04 '25 01:11

Bas