#include <stdio.h>
int main(int argc, char** argv)
{
signed char sc;
unsigned char uc;
short signed int ss;
short unsigned int us;
signed int si;
unsigned int ui;
long signed int sl;
long unsigned int ul;
long long signed int sll;
long long unsigned int ull;
for(sc = 1; (signed char)(sc << 1) > sc; sc <<= 1, sc |= 1);
for(uc = 1; (unsigned char)(uc << 1) > uc; uc <<= 1, uc |= 1);
for(ss = 1; (short signed int)(ss << 1) > ss; ss <<= 1, ss |= 1);
for(us = 1; (short unsigned int)(us << 1) > us; us <<= 1, us |= 1);
for(si = 1; (signed int)(si << 1) > si; si <<= 1, si |= 1);
for(ui = 1; (unsigned int)(ui << 1) > ui; ui <<= 1, ui |= 1);
for(sl = 1; (long signed int)(sl << 1) > sl; sl <<= 1, sl |= 1);
for(ul = 1; (long unsigned int)(ul << 1) > ul; ul <<= 1, ul |= 1);
for(sll = 1; (long long signed int)(sll << 1) > sll; sll <<= 1, sll |= 1);
for(ull = 1; (long long unsigned int)(ull << 1) > ull; ull <<= 1, ull |= 1);
printf("Maximum signed char:\t%hd\n", sc);
printf("Maximum unsigned char:\t%hu\n", uc);
printf("Maximum short signed int:\t%hd\n", ss);
printf("Maximum short unsigned int:\t%hu\n", us);
printf("Maximum signed int:\t%d\n", si);
printf("Maximum unsigned int:\t%u\n", ui);
printf("Maximum long signed int:\t%ld\n", sl);
printf("Maximum long unsigned int:\t%lu\n", ul);
printf("Maximum long long signed int:\t%lld\n", sll);
printf("Maximum long long unsigned int:\t%llu\n", ull);
return 0;
}
gcc运行结果:
Maximum signed char: 127
Maximum unsigned char: 255
Maximum short signed int: 32767
Maximum short unsigned int: 65535
Maximum signed int: 2147483647
Maximum unsigned int: 4294967295
Maximum long signed int: 2147483647
Maximum long unsigned int: 4294967295
Maximum long long signed int: 9223372036854775807
Maximum long long unsigned int: 18446744073709551615