Hey I have a question about the following code. It takes the powers of 50 numbers in a loop, and each function in the for loop outputs the same number. That is until it gets to loop 31. This line of code:
is not able to go past the 2 billion byte mark an integer can hold. I know that int variables cannot be bigger than 2.1 billion bytes, unless its a signed long int. But I'm curious on why the first line of code stated above can print larger numbers, and why the code below it can't exceed the 2.1 billion mark. Any ideas appreciated, thank you.
pow(2.0, i) is a double, which can represent a much larger number than in integer. arrayIntegers[i] = pow(2.0, i) converts the double to an integer (assuming arrayIntegers is an array of int).
It is NOT true that an int holds up to around 2 billion. That is the value for a 32 bit integer, but C++ does not require that int is 32 bits. See numeric_limits for the limits of different types. http://www.cplusplus.com/reference/limits/numeric_limits/