c ++中“unsigned long int”的最大值

时间:2021-03-10 22:29:28

How can I know what is the maximum assignable value for a variable from the the type of "unsigned long int"?

如何从“unsigned long int”的类型中知道变量的最大可赋值是多少?

3 个解决方案

#1


18  

The obvious way would be to use std::numeric_limits<unsigned long>::max();

显而易见的方法是使用std :: numeric_limits :: max();

#2


7  

Another way to find out would be:

找出的另一种方法是:

unsigned long int i = (unsigned long int) -1;
printf("%lu\n", i);

#3


2  

In simple way:

以简单的方式:

unsigned long int i = -1;
std::cout << i;

#1


18  

The obvious way would be to use std::numeric_limits<unsigned long>::max();

显而易见的方法是使用std :: numeric_limits :: max();

#2


7  

Another way to find out would be:

找出的另一种方法是:

unsigned long int i = (unsigned long int) -1;
printf("%lu\n", i);

#3


2  

In simple way:

以简单的方式:

unsigned long int i = -1;
std::cout << i;