Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

C++: I think I need a bigger datatype but even long long int is not working. Here is a screenshot of my code: http://imgur.com/VtRkB

myininaya (myininaya):

yucky computer programs lol

OpenStudy (anonymous):

lol

OpenStudy (anonymous):

how many "long" are you allowed to type?

OpenStudy (anonymous):

Figured this is a pretty simple question so I will try it here before I head over to stack overflow.

OpenStudy (anonymous):

imgur is giving me 404

OpenStudy (anonymous):

Why don't you pastebin the code its much better than a screenshot

OpenStudy (anonymous):

http://pastebin.com/

OpenStudy (anonymous):

http://pastebin.com/HenCRw7v

OpenStudy (anonymous):

I think only 2

OpenStudy (anonymous):

It depends on the platform but a signed integer is from -2^31 to 2^31

OpenStudy (anonymous):

This is the first time I've encountered something like this though so I am not even sure if I am doing it right typing any data type that is more than 1 word.

OpenStudy (anonymous):

A long signed integer is from -2^63 to 2^63

OpenStudy (anonymous):

*long long

OpenStudy (anonymous):

one second.

OpenStudy (anonymous):

I am using dev c++

OpenStudy (anonymous):

Also you forgot to initialize the variable to 0

OpenStudy (anonymous):

So it will simply take on the value that was there before it on the stack.

OpenStudy (anonymous):

long long int n = 0;

OpenStudy (anonymous):

Ok

OpenStudy (anonymous):

Same error

OpenStudy (anonymous):

"integer constant is too large for "long" type"

OpenStudy (anonymous):

Don't need int just long long

OpenStudy (anonymous):

long long n = 0;

OpenStudy (anonymous):

Fine now?

OpenStudy (anonymous):

No, same error

OpenStudy (anonymous):

Hmm

OpenStudy (anonymous):

ah ok I think I know what will help Its complaining about the literal try adding an l after the number or ll

OpenStudy (anonymous):

600851475143ll I think

OpenStudy (anonymous):

That did it

OpenStudy (anonymous):

Cool, what does that mean?

OpenStudy (anonymous):

its a long long literal

OpenStudy (anonymous):

Anytime you have long or long long you need l or ll?

OpenStudy (anonymous):

l is just long, ll is long long

OpenStudy (anonymous):

Im sure you've seen something similar for floating point values

OpenStudy (anonymous):

for instance 3.0f

OpenStudy (anonymous):

never

OpenStudy (anonymous):

alright

OpenStudy (anonymous):

in any case be very careful with your types if you are going to be handling long long values

OpenStudy (anonymous):

you don't want to truncate it at some point in the program

OpenStudy (anonymous):

Ok, thanks a lot!

OpenStudy (anonymous):

Actually one last thing, long is the implicit type for integer literals (at least for your compiler). So you only need ll for long long literals, for smaller values you do not need to explicitly append a single "l"

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!