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

方法一:自力更生

#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;
} 

猜你喜欢

转载自blog.csdn.net/vocaloid01/article/details/81253652
今日推荐