putting value of struct in runtme

Solutions on MaxInterview for putting value of struct in runtme by the best coders in the world

showing results for - "putting value of struct in runtme"
Cristina
05 Jun 2016
1my struct operations
2
3C offers you:
4
5struct initialization (only at declaration time):
6
7struct Student s1 = {1, "foo", 2.0 }, s2;
8struct copy:
9
10struct Student s1 = {1, "foo", 2.0 }, s2;
11s2 = s1;
12direct element access:
13
14struct Student s1 ;
15s1.id = 3;
16s1.name = "bar";
17s1.score = 3.0;
18manipulation through pointer:
19
20struct Student s1 = {1, "foo", 2.0 }, s2, *ps3;
21ps3 = &s2;
22ps3->id = 3;
23ps3->name = "bar";
24ps3->score = 3.0;
25initialization function:
26
27void initStudent(struct Student *st, int id, char *name, double score) {
28    st->id = id;
29    st->name = name;
30    st->score = score;
31}
32...
33int main() {
34    ...
35    struct Student s1;
36    iniStudent(&s1, 1, "foo", 2.0);
37    ...
38}