1
0
This commit is contained in:
2025-10-10 02:17:07 +02:00
commit ee9f86004b
48 changed files with 2161 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#include "smt4497-P2.h"
int p2_struct_union()
{
setlocale(LC_ALL, "spanish");
printf("\nEstructuras | PR<50>CTICA 2 | SS\n");
printf("---------------------------------\n");
struct {
int entero;
char car;
} vEstructura = { 256, 1 }; // Define + inicializa la estructura
union {
int entero;
unsigned char car[4];
} vUnion = { 256 }; // Define + inicializa la uni<6E>n
vUnion.entero = 0x89abcdef; // byte 0: 0xef, byte 1: 0xcd, byte 2: 0xab, byte 3: 0x89
printf("vUnion.entero vale 0x%x\n", vUnion.entero);
printf("El valor del byte 2 de vUnion.entero es: 0x%x\n",
// (vUnion.entero & 0x00ff0000) >> 16); tambi<62>n es v<>lido hacer primero la m<>scara y luego shift
(vUnion.entero >> (8 * 2) & 0xff));
printf("El valor del byte 2 de vUnion.entero es: 0x%x\n",
vUnion.car[2]);
// printf("Estructura: %d Tam: %d\n", vEstructura.entero, sizeof(vEstructura));
// printf("Union: %d Tam: %d\n", vUnion.entero, sizeof(vUnion));
return 0;
}