how do i pass a 32 bit number into an ‘int’ variable without anything above 0x7fffffff being considered negative?

You can’t, unless you find a platform with an int that’s larger than 32 bits (they are at the time of writing rare).

If you need to use a signed type, then std::int64_t is a good choice. Or long long is also guaranteed to be large enough.


If you’re absolutely constrained by the interface to your function then you could break your number up into two parts – and adopt the convention that you need to call the function twice to get anything meaningful out of it. But that could make your program very brittle.


Another option: if your function is allowed to take the int by reference then you could have an array of two ints at the call site, and pass the first one to your function. You can then reach the other using pointer arithmetic within the function body! Again, this will make your code brittle but it would work.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top