#include <stdio.h>
void main(void)
{
int nMin = 8;
unsigned int* pMin = (unsigned int*)&nMin;
while(0 != (*pMin << 4)) *pMin <<= 4;
printf("INT_MIN: %d\n", nMin);
}
#include <stdio.h>
void main(void)
{
int nMin = 8;
int nMax = 0;
int nWidth = 8;
while(0 < (nMin <<= 4)) nWidth += 4;
nMax = nMin^-1;
printf("Integers on your system are %d bits wide.\n", nWidth);
printf("The maximum integer is %d.\n", nMax);
printf("The minimum integer is %d.\n", nMin);
}
1 << (sizeof(int) * 8 - 1)
#include <stdio.h>
#include <limits.h>
int main(int argc, char* argv[])
{
printf("%d %d\n", 1 << (sizeof(int) * 8 - 1), INT_MIN);
return 0;
}
But it's probably better to #include <limits.h> and use INT_MIN
You could use this snippit:Code:1 << (sizeof(int) * 8 - 1)
But it's probably better to #include <limits.h> and use INT_MIN
(as far as I know, limits.h and INT_MIN are cross-platform.)
Well, first off I assumed "programmatically" meant "calculate it," but second, check /usr/include/limits.h before you make any assumptions. I checked that first, and you'll be surprised.
I assumed "programmatically" meant "calculate it
int minlimit = (int)( ( ( (unsigned int) -1 ) >> 1 ) + 1 ) ;