mardi 14 janvier 2020

warning: overflow in implicit constant conversion [-Woverflow]| even tough using long [duplicate]

This question already has an answer here:

Hey guys i am writing a backtrack program but i have a little problem though. There is one variable i am using to safe all the candidates to. The candidates are: 9876543210, so the variable will be: long int x = 9876543210.

But for some reason the program initialize x as 1286608618.

Though I saved x as long int. So I tried a small main program looking like this:

#include <iostream>

using namespace std;

int main()
{
   long int x = 9876543210L; 
   cout << x; 
}

If I compile the code the compilers tells me: "warning: overflow in implicit constant conversion [-Woverflow]".

I am using the GNU GCC Compiler.

Do you guys know why?

Aucun commentaire:

Enregistrer un commentaire