-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.c
37 lines (31 loc) · 1.11 KB
/
struct.c
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
#include<stdio.h>
#include <string.h>
// Persona es un tag
struct Persona { //Alojado continuo de objetos
char name[50];
int edad;
} persona, *persona_p;
union { //Memoria compartida entre dos estructuras, se sobre escriben los objetos
struct {
char name[50];
} pn;
struct {
char name[50];
int edad;
} pne;
} personas;
int main(){
strcpy(persona.name, "Fran");
persona.edad = 23; // . operador de miembro de estructura
printf("%s tiene %d a%cos\n", persona.name, persona.edad, 164);
persona_p = &persona; //Asignamos al puntero la dirección de la estructura
printf("%s tiene %d a%cos\n", persona_p->name, persona_p->edad, 164);
/* El operador de puntero de estructura referencia
* los miembros desde un puntero a una estructura.*/
personas.pne.edad = 50;
strcpy(personas.pne.name, "Francisco");
strcpy(personas.pn.name, "Paco");
printf("%s\n", personas.pn.name); // (!) paco sobre escribe a Francisco
printf("%s tiene %d a%cos\n", personas.pne.name, personas.pne.edad, 164);
return 0;
}