0% found this document useful (0 votes)
29 views

Structuri

This document defines several C++ structs and unions to represent complex numbers, points, nodes, and linked lists. It declares variables of these types and demonstrates accessing their members and dereferencing pointers to them. It also defines mutually recursive structs to represent linked data and demonstrates printing their members.

Uploaded by

Adriana
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Structuri

This document defines several C++ structs and unions to represent complex numbers, points, nodes, and linked lists. It declares variables of these types and demonstrates accessing their members and dereferencing pointers to them. It also defines mutually recursive structs to represent linked data and demonstrates printing their members.

Uploaded by

Adriana
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1: #include <iostream>

2: #include <stdlib.h>
3:
4: using namespace std;//pt scrierea prescurtata, fara std::cout, etc
5:
6: int main()
7: {
8: typedef struct {
9: float re;
10: float im;
11: } complex;
12:
13: struct punct {
14: int x;
15: int y;
16: };
17:
18: complex z1 = {1, 3}, *pz1 = &z1;
19: punct P1 = {1, 2}, *pP1 = &P1, P2 = P1;
20:
21: cout << z1.re << "\t" << z1.im << endl;
22: cout << pz1 -> re << "\t" << pz1 -> im << endl;
23:
24: cout << P1.x << "\t" << P1.y << endl;
25: cout << pP1 -> x << "\t" << pP1 -> y << endl;
26:
27: /* struct nod {
28: int informatie;
29: nod *urmatorul;
30: };
31:
32: typedef nod *pnod;
33:
34: nod n1;
35: pnod pn2;
36: n1.informatie = 10;
37: n1.urmatorul = NULL;
38:
39: pn2 = new nod;
40: pn2->informatie = n1.informatie;
41: pn2->urmatorul = NULL;
42:
43: cout << n1.informatie << "\t" << pn2->informatie << endl;
44: pn2->informatie = 20;
45: cout << n1.informatie << "\t" << pn2->informatie << "\t" << pn2->urmatorul
<< endl;
46: */
47:
48:
49: typedef struct nod {
50: int informatie;
51: nod *urmatorul;
52: } NOD, *PNOD;
53:
54:
55: NOD n1;
56: PNOD pn2;
57: n1.informatie = 10;
58: n1.urmatorul = NULL;
59:
60: pn2 = new NOD;
61: pn2->informatie = n1.informatie;
62: pn2->urmatorul = NULL;
63:
64: cout << n1.informatie << "\t" << pn2->informatie << endl;
65: pn2->informatie = 20;
66: cout << n1.informatie << "\t" << pn2->informatie << "\t" << pn2->urmatorul
<< endl;
67:
68: struct a {
69: int informatieA;
70: struct b *pb;
71: };
72:
73: struct b {
74: int informatieB;
75: struct a *pa;
76: };
77:
78: a varA1;
79: b varB1;
80:
81: varA1.informatieA = 10;
82: varA1.pb = &varB1;
83: varB1.informatieB = 20;
84: varB1.pa = &varA1;
85: cout << varA1.informatieA << "\t" << varA1.pb->informatieB << endl;
86:
87: /* union uniune {
88: int valoareIntreaga;
89: float valoareReala;
90: char *variabilaText;
91: };
92: */
93:
94: typedef union {
95: int valoareIntreaga;
96: float valoareReala;
97: char *variabilaText;
98: } uniune;
99:
100: uniune u1;
101: uniune *pu1 = &u1;
102:
103: u1.valoareIntreaga = 13;
104: cout << u1.valoareIntreaga << "\t" << u1.valoareReala << endl;
105: u1.variabilaText = "Test";
106: cout << u1.valoareIntreaga << "\t" << u1.valoareReala << "\t" <<
u1.variabilaText << endl;
107: cout << pu1->valoareIntreaga << "\t" << pu1->valoareReala << "\t" << pu1-
>variabilaText << endl;
108:
109: system("PAUSE");//in stdlib
110: return 0;
111: }
112:
113:
114:
115:
116:

You might also like