Question:
Why do I get the warning: ``overflow in implicit constant conversion`` when defining an int as a large number?
barb
2010-02-06 10:15:16 UTC
If I write:

int num = 13195;

my program works correctly and generates the correct answer.

If I change it to
int num = 600851475143;

I get that warning and my program doesn`t generate any answer. What do I do to get an answer

Written in C
Five answers:
dolchio
2010-02-06 10:38:28 UTC
The value is too large for an int. The memory allocates 4 bytes to an int data type, meaning the largest possible value that can be stored is 4 294 967 296, which is about 100 times smaller than your value. Try declaring it as either a long integer or a float.



long int num = 600851475143;



float num = 600851475143;



a long int has 8 bytes allocated to it, allowing you to store very large numbers in it.



a float is still allocated 4 bytes but the number is represented in a different way and will allow you to store the value.
?
2016-11-16 06:53:39 UTC
Overflow In Implicit Constant Conversion
2015-08-08 12:36:36 UTC
This Site Might Help You.



RE:

Why do I get the warning: ``overflow in implicit constant conversion`` when defining an int as a large number?

If I write:



int num = 13195;



my program works correctly and generates the correct answer.



If I change it to

int num = 600851475143;



I get that warning and my program doesn`t generate any answer. What do I do to get an answer



Written in C
2010-02-06 10:26:36 UTC
A signed int has the range -32767 to +32767.



Use a larger data type such as float / double.

http://home.att.net/~jackklein/c/inttypes.html
Bored
2010-02-06 10:28:44 UTC
You should read this as well

http://www.cplusplus.com/doc/tutorial/variables/


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...