阅读下面的代码片段,回答问题:
void main(void){int g = 0;for(int i = 0; i <= 30 ; i++){g=g+(int)pow(2.0 , i*1.0);}g=g+1;printf("%d" , g);return ;}
这段代码的输出是否为 0,为什么?提示:带符号的 int 类型最大表示数字为:+2147483647
daan:
#include#include int main(void){ int g = 0; for(int i = 0; i <= 30 ; i++) { g=g+(int)pow(2.0 , i*1.0); } g=g+1; printf("2ex31=%d\n" , g); printf("2ex31=%d\n",(int)pow(2,31)); printf("2ex32=%d\n",(int)pow(2,32)); return 0;}/*打印出基本数据类型能保存的最大数与最小数*//*#include #include #include using namespace std;int main(){ cout << "type: \t\t" << "************size**************"<< endl; cout << "bool: \t\t" << "所占字节数:" << sizeof(bool); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "char: \t\t" << "所占字节数:" << sizeof(char); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "signed char: \t" << "所占字节数:" << sizeof(signed char); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "short: \t\t" << "所占字节数:" << sizeof(short); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "int: \t\t" << "所占字节数:" << sizeof(int); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "long: \t\t" << "所占字节数:" << sizeof(long); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "double: \t" << "所占字节数:" << sizeof(double); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "long double: \t" << "所占字节数:" << sizeof(long double); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "float: \t\t" << "所占字节数:" << sizeof(float); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "size_t: \t" << "所占字节数:" << sizeof(size_t); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "string: \t" << "所占字节数:" << sizeof(string) << endl; // << "\t最大值:" << (numeric_limits ::max)() << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "type: \t\t" << "************size**************"<< endl; return 0;}*/