0

Here's the piece of code

long int lValue = 9999999999999; cout << lValue << endl; 

I am running it on Eclipse IDE for C/C++, using MinGW compiler.

I have include the #include <limits.h> properly and other sort of short and unsigned int are being compiled and showing a value properly.

But while running this long int value, I am getting the following value. 1316134911 instead of the original value, I tried it with different values but each time it's getting a random value. Any more details required? let me know, thanks in advance!

3

2 Answers 2

2

You need to use long long if you want to store 64 bits (and you do).

 const auto lValue = 9999999999999LL; 

or

 long long lValue = 9999999999999LL; 
Sign up to request clarification or add additional context in comments.

Comments

1

Add a L to the end of your 9's.

6 Comments

The same value is being generated.
@Saw do you have any optimization flags enabled when compiling?
@Freddy none as of I know, I am new to Eclipse. Can you please route me to the location on how I can find this optimization flags?
LL will be a long long, which is always at least 64 bits. L is long which is 64 bits on Linux but 32 bits on Windows.
Why can't we all just get a long?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.