Record Size:

  

struct studentinfo {   struct studentinfo *previousgpa;          4 bytes

                                    char ssn[11], name[28], address[30];   11 + 28 + 30 = 69 Bytes

                                    short age, IQ;                                          2 + 2 = 4 Bytes

                                    float gpa, balance;                                  4 + 4 = 8 Bytes

                                    struct studentinfo *nextbalance; };      4 Bytes

                                                                                                      ---

                                                                                                      89 Bytes

 

Given:    printf (“%lu\n”, &student[2].name);  yields the output:   8625

Then:    &student[2] => 8625  - 11 – 4 = 8610

And:       student = 8610 – 2 * 89 = 8610 – 178 = 8432

 

The Linked Table below shows all of the addresses and links:

 

Highgpa                  Lowbalance

 

8432

8788

 

 

Addr

Sub

Previgpa

ssn

name

address

age

IQ

gpa

balance

nextbal

8432

0

8521

1234…

Gates

99 Microsoft

47

108

3.87

4500

NULL

8521

1

8699

2345…

Ford

17 Michigan

125

115

3.10

250

8699

8610

2

NULL

3456…

Trump

1 Trump

65

86

1.86

1500

8432

8699

3

8788

4567…

Astor

20 Wall

116

100

2.76

800

8610

8788

4

8610

5678…

Carnegie

100 Steel

81

79

2.25

0

8521

 

 

For each of the following printf statements, show the output which would be obtained:

 

a.          printf(“%lu\n”,highgpa);                                       8432

b.          printf(“%lu\n”,&highgpa);                                     Unknown (this is NOT a trick question)

c.          printf(“%lu\n”,lowbalance);                                  8788                                                                                                  

d.          printf(“%s\n”, student[4].previousgpa->previousgpa);           8610 -> NULL

e.          printf(“%lu\n”,&student[2]. IQ);

 

                         &student[2] == 8610, so  &student[2].IQ == 8610 + 4 +11 + 28 + 30 = 8683

 

f.            printf(“%s\n”,student[3].nextbalance->nextbalance->name);

 

                                 8610 ->  8432  ->  Gates

 

g.          printf(“%lu\n”, ++lowbalance);                             8788 + 89 = 8877

 

h.          if I first enter the command:  arecord = record[4].nextbalance; what will be printed out by the command:

                                                         

        printf(“%d\n\n”, ++arecord->age); arecord = 8521

                                                                                     ++arecord = 8521 + 89 = 8610

                                                                                     8610 -> age = 65

 

a.     printf(“%lu\n”,&student[10].address);                       BA + offset * #bytes/record + field offset

                                                                                     = 8432 + 10 * 89 + 4 + 11 + 28

                                                                                     = 9372