user2517676
user2517676

Reputation: 989

The maximum value of "unsigned long int" in c++

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

Upvotes: 11

Views: 15145

Answers (3)

Jerry Coffin
Jerry Coffin

Reputation: 490338

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

Upvotes: 33

user3451749
user3451749

Reputation:

In simple way:

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

Upvotes: 5

Jeremy Friesner
Jeremy Friesner

Reputation: 73161

Another way to find out would be:

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

Upvotes: 6

Related Questions