Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. A record and a variable are declared as follows: struct NameType { char first

ID: 3674509 • Letter: 1

Question

1. A record and a variable are declared as follows: struct NameType { char firstName[17]; char lastName[17]; int age; float salary; }; NameType employee[10]; The base address of employee is stored in memory location 2000. Assume that a char takes 1 memory location, an int takes 2 locations, and a float number takes 4 locations. (a) Write the member-length table for NameType Member c Length firstName    lastName    age    salary    (b) How many memory locations does one NameType variable take? (Or, what is the size of the Nametype struct?) (c) What is the address of the member firstName of employee[5] ? (d) What is the address of employee[5].age ? (e) What is the address of employee[5].lastName[4]? 1. A record and a variable are declared as follows: struct NameType { char firstName[17]; char lastName[17]; int age; float salary; }; NameType employee[10]; The base address of employee is stored in memory location 2000. Assume that a char takes 1 memory location, an int takes 2 locations, and a float number takes 4 locations. (a) Write the member-length table for NameType Member c Length firstName    lastName    age    salary    (b) How many memory locations does one NameType variable take? (Or, what is the size of the Nametype struct?) (c) What is the address of the member firstName of employee[5] ? (d) What is the address of employee[5].age ? (e) What is the address of employee[5].lastName[4]? 1. A record and a variable are declared as follows: struct NameType { char firstName[17]; char lastName[17]; int age; float salary; }; NameType employee[10]; The base address of employee is stored in memory location 2000. Assume that a char takes 1 memory location, an int takes 2 locations, and a float number takes 4 locations. (a) Write the member-length table for NameType Member c Length firstName    lastName    age    salary    (b) How many memory locations does one NameType variable take? (Or, what is the size of the Nametype struct?) (c) What is the address of the member firstName of employee[5] ? (d) What is the address of employee[5].age ? (e) What is the address of employee[5].lastName[4]?

Explanation / Answer

struct NameType

{

char firstName[17]; //17byte

char lastName[17]; //17byte

int age; //1byte

float salary; //4 byte

};

NameType employee[10];

a)Member c Length

Member

C-Length

firstName

17*10=170byte

lastName

17*10=170byte

age

1*10=10byte

salary

4*10=40byte

(b)Size of NameType variable take

=17 bytes for firstName+17 bytes for lastName+1byte for age+4 byte for salary

=34+1+4

=39bytes

Therefore, one NameType variable takes 39 bytes

c)

Address of the member firstName of employee[5] ?

=Base Address+5*Size of NameType Variable

=2000+5*39

=2000+195

=2195

(d) Address of employee[5].age

=Base Address+5*Size of NameType Variable + Size of first name+ Size of last name

=2000+5*39+17+17

=2000+195+34

=2195+34

=2229

(e) Address of employee[5].lastName[4]

= Base Address + 5*Size of NameType Variable + Size of firstName+ 4 Bytes from lastName

= 2000+5*39+17+4

=2216

Member

C-Length

firstName

17*10=170byte

lastName

17*10=170byte

age

1*10=10byte

salary

4*10=40byte