Ive been playing around with some code. When running the first code, i get an answers, but when running the second lot I get 0. The only diffrence is that I change the power from 29 to 30. Could someone help explain this or a way around it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int pow2(int n){
int result=1;
for (int i=0;i<n;i++){
result*=2;
}
return result;
}
#include <iostream>
int main()
{
std::cout << pow2(29) << '\n' ;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int pow2(int n){
int result=1;
for (int i=0;i<n;i++){
result*=2;
}
return result;
}
#include <iostream>
int main()
{
std::cout << pow2(30) << '\n' ;
}