blob: fe8969668ee1f9546a81a8ca195560b3a9b4f819 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include <stdio.h>
void printu(int size);
void prints(int size);
/* prints the range of values for char, short, int and long */
int main(int argc, char *argv[]) {
printf("char: ");
prints(sizeof(char));
printf("unsigned char: ");
printu(sizeof(unsigned char));
printf("short: ");
prints(sizeof(short));
printf("unsigned short: ");
printu(sizeof(unsigned short));
printf("int: ");
prints(sizeof(int));
printf("unsigned int: ");
printu(sizeof(unsigned int));
printf("long: ");
prints(sizeof(long));
printf("unsigned long: ");
prints(sizeof(unsigned long));
return 0;
}
void printu(int size) {
int bits = size << 3;
printf("0 to %ld\n", (1L << (bits - 1)) + ((1L << (bits - 1)) - 1));
}
void prints(int size) {
int bits = size << 3;
printf("%ld to %ld\n", -(1L << (bits - 1)), (1L << (bits - 1)) - 1);
}
|