-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL13_Structure.c
More file actions
214 lines (167 loc) · 2.73 KB
/
Copy pathL13_Structure.c
File metadata and controls
214 lines (167 loc) · 2.73 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
void structureDemo()
{
struct
{
int id;
char name[10];
int age;
char gender;
}emp1,emp2;
//.
emp1.id = 10;
emp1.age = 20;
emp1.gender = 'm';
strncpy(emp1.name,"abc",10);
printf("Id:%d,\n",emp1.id);
printf("Age:%d,\n",emp1.age);
printf("Gender:%c,\n",emp1.gender);
puts(emp1.name);
}
void structureArray()
{
struct Emp
{
int id;
char name[10];
int age;
char gender;
};
struct Emp empArray[10];
empArray[0].id = 1;
empArray[0].age = 20;
empArray[0].gender = 'f';
empArray[1].id = 2;
empArray[1].age = 22;
empArray[1].gender = 'f';
empArray[2].id = 3;
empArray[2].age = 23;
empArray[2].gender = 'm';
displayEmpData(empArray[0].id,empArray[0].age,empArray[0].gender);
displayEmpData(empArray[2].id,empArray[2].age,empArray[2].gender);
printf("Id:%d | AGE:%d | GENDER :%c\n ",empArray[1].id,empArray[1].age,empArray[1].gender);
}
void structValAsParam()
{
struct Emp
{
int id;
char name[10];
int age;
char gender;
}emp1;
emp1.id = 1;
emp1.age = 20;
emp1.gender = 'm';
displayEmpData(emp1.id,emp1.age,emp1.gender);
}
struct Emp
{
int id;
char name[10];
int age;
char gender;
};
void structAsParam()
{
struct Emp emp1;
emp1.id = 1;
emp1.age = 20;
emp1.gender = 'm';
displayEmp(emp1);
}
void displayEmp(struct Emp empData)
{
printf("======Emp Data=======\n");
displayEmpData(empData.id,empData.age,empData.gender);
printf("\n======Emp Data=======");
}
void displayEmpData(int id,int age,char gender)
{
printf("ID: %d \n",id);
printf("Age: %d\n",age);
printf("Gender: %c",gender);
}
void structurePointer()
{
// int a = 10 //123
// int *b = &a;
// int c = *b;
// *,&,->
struct Emp emp1;
struct Emp *emp2;
emp1.age = 10;
printf("%d",emp1.age);
emp2 = &emp1;
printf("%d",emp2->age);
structPointerFunc(&emp1);
printf("%d",emp1.age);
}
void structPointerFunc(struct Emp *empData)
{
empData->age = 20;
}
struct Record
{
struct Emp emp1;
int names[10][10];
};
void structAndArrayInsideStruct()
{
struct Record record1;
record1.emp1.age = 10;
record1.emp1.id = 1;
strncpy(record1.names[0],"abc",10);
printf("Age:%d\n",record1.emp1.age);
puts(record1.names[0]);
}
void unionDemo()
{
union data
{
int type;
char val;
int type2;
}dataVar;
dataVar.type = 97;
printf("Type:%d\n",dataVar.type);
printf("Val:%c\n",dataVar.val);
printf("type2:%d\n",dataVar.type2);
}
void enumDemo()
{
enum Direction
{
//int North = 1;
//int East = 2;
North=1,East,West,South
};
printf("%d",South);
int direction;
scanf("%d",&direction);
printf("%d",direction);
switch(direction)
{
case North:
printf("North");
break;
case East:
printf("East");
break;
case West:
printf("West");
break;
case South:
printf("South");
break;
default:
printf("No direction found");
}
}
void typedefDemo()
{
char ch;
int a;
typedef char Char;
Char mychar = 'A';
printf("%c",mychar);
}