Maximum value for unsigned int

Here is what I want:

unsigned int max_unsigned_int_size; max_unsigned_int_size = ???; 

How can I do it?

+7
source share
6 answers

C

 #include <limits.h> unsigned int max_unsigned_int_size = UINT_MAX; 

C ++

 #include <limits> unsigned int max_unsigned_int_size = std::numeric_limits<unsigned int>::max(); 
+29
source
 unsigned int max_unsigned_int_size = -1; 

correct operation guaranteed. Arithmetic with unsigned types is always modulo.

But in a specific case, you should always use UINT_MAX

+11
source

You are looking for

 #include <limits> std::numeric_limits<unsigned int>::max(); 

If you want size, sizeof will do, multiply CHAR_BITS to get the bit.

Alternatively there is

 std::numeric_limits<unsigned int>::digits(); 
+6
source

You need std::numeric_limits::max()

 #include <limits> ... max_insigned_int_size = std::numeric_limits<unsigned int>::max(): 
+4
source
  • For C, the value is set to UINT_MAX in limits.h .
  • For C ++, you can also use std::numeric_limits<unsigned int>::max() from limits .
+2
source
 #include <limits> max_unsigned_int_size = std::numeric_limits<unsigned int>::max(); 
+1
source

All Articles