r305_dm/Exo5/alignement.c

69 lines
996 B
C
Raw Normal View History

2023-09-07 15:38:31 +02:00
/* alignement et objets */
struct exemple1 {
int x;
int y;
int z;
int w;
};
struct exemple2 {
char x;
char y;
char z;
char w;
};
struct exemple3 {
int x;
int y;
char z;
char w;
};
struct exemple4 {
int x;
char y;
int z;
char w;
};
union exemple5 {
int x;
char y;
int z;
char w;
};
int main()
{
int a[4] = {1,2,3,4};
char c[4] = {'a','b','c','d'};
struct exemple1 ex1 = {1,2,3,4};
struct exemple2 ex2 = {'a','b','c','d'};
struct exemple3 ex3 = {1,2,'c','d'};
struct exemple4 ex4 = {1,'c',2,'d'};
union exemple5 ex5;
int x = 61;
char y = 62;
int z = 63;
char w = 64;
ex5.x=62;ex5.y=63;ex5.z=64;ex5.w=65;
// appelez hexdump pour chaque variable
2023-09-13 19:57:20 +02:00
hexdump(a, sizeof(a));
hexdump(c, sizeof(c));
hexdump(&ex1, sizeof(ex1));
hexdump(&ex2, sizeof(ex2));
hexdump(&ex3, sizeof(ex3));
hexdump(&ex4, sizeof(ex4));
hexdump(&ex5, sizeof(ex5));
hexdump(&x, sizeof(x));
hexdump(&y, sizeof(y));
hexdump(&z, sizeof(z));
hexdump(&w, sizeof(w));
return 0;
2023-09-07 15:38:31 +02:00
}