Such arbitrary big values can't be held in a 4-bytes integer datatype (if you're using a 64-bit machine). Yet if you're not sure which type is appropriate to fit in it, take the help of auto
:
#include <iostream>
void getNums() {
// 'long int' after type deduction
auto i = 99999999999999999;
std::cout << i << std::endl;
}
int main(void) {
getNums();
return 0;
}
In my case, the i
is deducted into a type of long
. It may differ on your system since the architecture may differ.
On the other hand, in case you want to do-it-yourself and see the largest number a 4-bytes (i.e. 32-bits) integer could hold, you could use limits
:
void getNums() {
// 4-bytes integer on 64-bit machine
// expands to 2,147,483,647 in my 64-bit system
auto i = std::numeric_limits<int>::max();
std::cout << i << std::endl;
}
Lastly, consider enabling the compiler warnings. This'll help you a lot.
Referring to a Data Type Ranges if you want to understand better.