its not talkin long long a=111111111111(12 1's)

well in one code if i assign a=12 1's its showing tht "integer constant is too large for ‘long’ type"
but if i go through loop
for(;a<x;a=a*10+1);
where x is long long.it can take up a=111111111111(same as above).n shows no error.
since both are same values its showing error if i assign it directly in d beginning,but its fine if it eventually computed tht in a loop.
hope i am clear enof.
A 32-bit signed integer's upper limit is 2,147,483,647. You're trying to put 11,111,111,111 in it.
Integral literals in C/C++ are interpreted as type "int" by default unless a type override is specified.

Try

 
long long x = 111111111111LL;  // LL means treat literal as long long 


or try double x

int can only hold so many numbers, there are other ways to expand it, long long x like jsmith said,
theres long x, double, int, can't remeber anymore if there are any.

signed = only a positive number
unsigned = only negative number

not sure if thats right, but they allow you to use more numbers. For a number with 12 1's it is probably best to use double.

just put double x instead of int x. HTH, also feel free to correct me if i'm wrong and as helios said , int can hold at the max: 2,147,483,647 anymore and u have to change data type (int, char, double, float etc...)
@rej3kt:

?

signed means the value has sign, meaning it can hold positive and negative numbers.
unsigned means the value has no sign (meaning it can hold only non-negative numbers).

But the solution to "my integer can't store a number large enough" is rarely ever to switch
to floating point arithmetic; floating point has a whole other set of issues that integer
arithmetic does not have. If C++ does not have an integral POD-type large enough, then
OP should consider a bigint library such as GMP (and there are others).

thanks for correcting me I was obviously wrong lol
but my problem is not about storing large number in int.its about how that big number is gettin stored in int if i use that loop but it shows error if i assign tht value directly during starting of my programme
Post your code.
Unless your number just had to be an integer, I would just set your number as a float and divide it by 1000 to make it 11111111.111 which float can hold. then if you need to do something with it in your program, just multiply it by 1000 and its 11 billion again.

set your number as a float and divide it by 1000 to make it 11111111.111 which float can hold. then if you need to do something with it in your program, just multiply it by 1000 and its 11 billion again.
It's almost like magic! 32-bit floating point variables can hold more information than 32-bit integral variables!
Last edited on
Topic archived. No new replies allowed.