Author Options:

How do I store a very big number into a variable in C? Answered

I'm using Dev-c++ (Bloodshed) and I need to store 3 billion into a variable, I already tried:

int bla = pow(10,9) * 3
long int bla = pow(10,9) * 3
long long int bla = pow(10,9) * 3
signed int bla = pow(10,9) * 3

Then I tried to modify printf, guessing it might be the print function instead of var itself, but every urr 'var argument' didn't seem to work;


But whatever I do, the max number seems to be '2147483647'.
Help pl0x, I'm confused because wiki says that 'long long int' should result in a 64 bit var, apparently not so.. (32 bit processor).

(It should be possible without fancy headers I heard)


The forums are retiring in 2021 and are now closed for new topics and comments.

Best Answer 11 years ago

Why are you using integers? pow() returns a double.

double large = pow(10,9)*3.;

Also, are you really writing the expressions above with numeric constants? Or were those just examples? pow() is an expensive function -- both of its arguments are doubles, and it uses logs and exponentials to do the math. If you really just need the static value "three billion", you should write "3e+9" and be done with it.


11 years ago

Hmm odd, the compiler didn't even give a warning that the value POW() returns is a double.. anywho, 3e9 is indeed a better solution.

Thanks =)