巧得int(4字节)最大最小值

  • Post author:
  • Post category:其他



方法一:自力更生

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	unsigned int a = 0;
	int MAX_int = (~a)/2;
	cout<<MAX_int<<endl;

	return 0;
} 

可以得到int最大值为

2147483647

,而根据常识我们可以知道int最小值一定为

-2147483648(

不知道的重学机组吧



注意a必须为unsigned int。


方法二:头文件

<limits.h>/<climits>

中定义了宏:INT_MAX和INT_MIN可以拿来直接用

#include <climits>
#include <iostream>

using namespace std;

int main(){
	
	cout<<INT_MAX<<endl;
	cout<<INT_MIN<<endl;

	return 0;
} 



版权声明:本文为vocaloid01原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。