int型的最大值、最小值 c++
·
int型的最大值、最小值
C/C++中int类型是32位的,范围是-2147483648到2147483647 。
INT_MIN 和 INT_MAX
int max = (1<<31)-1;//这里要加括号,运算符优先级
int min = 1<<31;//由于int是32位的
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
int max_int = (1<<31) -1;
int min_int = 1 << 31;
cout<<max_int<<" "<<min_int<<endl;
return 0;
}
结果
Hello, World!
2147483647 -2147483648
Program ended with exit code: 0
所以可以写成
func getMinInt {
return 1 << 31;
}
func getMaxInt {
return (1 << 31) - 1;
}
golang里的表示方法
// Integer limit values.
const (
MaxInt8 = 1<<7 - 1
MinInt8 = -1 << 7
MaxInt16 = 1<<15 - 1
MinInt16 = -1 << 15
MaxInt32 = 1<<31 - 1
MinInt32 = -1 << 31
MaxInt64 = 1<<63 - 1
MinInt64 = -1 << 63
MaxUint8 = 1<<8 - 1
MaxUint16 = 1<<16 - 1
MaxUint32 = 1<<32 - 1
MaxUint64 = 1<<64 - 1
)

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
更多推荐
所有评论(0)