update
[sws1-1415.git] / ass2 / mart / sws1-s4109503-s4202015 / exercise2.c
1 #include <stdio.h>
2
3 void pm(unsigned char *a, size_t s)
4 {
5 for(unsigned char *i = a; i < a+s; i++)
6 printf("%p\t0x%02X\t\t%3u\n", i, *i, *i);
7 }
8
9 int main(void)
10 {
11 short i = 0x1234;
12 char x = -127;
13 long sn1 = 4109503;
14 long sn2 = 4202015;
15 int y[2] = {0x11223344, 0x44332211};
16 printf("short i = %zu byte(s)\n", sizeof(i));
17 printf("char x = %zu byte(s)\n", sizeof(x));
18 printf("long sn1 = %zu byte(s)\n", sizeof(sn1));
19 printf("long sn2 = %zu byte(s)\n", sizeof(sn2));
20 printf("int[2] y = %zu byte(s)\n\n", sizeof(y));
21 printf("address\t\tcontent (hex)\tcontent(dec)\n");
22 printf("--------------------------------------------\n");
23 pm((unsigned char *)&i, sizeof(i));
24 pm((unsigned char *)&x, 1);
25 pm((unsigned char *)&sn1, sizeof(sn1));
26 pm((unsigned char *)&sn2, sizeof(sn2));
27 pm((unsigned char *)&y, sizeof(y));
28 return 0;
29 }