問題
同級生と私は、メモリを数えて最後の問題の開始アドレスを見つけるのに苦労しています (以下を参照)。users[20].userinfo.donor.amount[1] の開始アドレスを見つけるためにユニオン内のバイトをカウントする方法がわかりません。
私たちの教授によると、答えは 8009 です。これは正しいですか。
Assume that a char = 1 byte, int = 4 bytes, double = 8 bytes, and pointers are 4 bytes.
struct address {
char street[100];
char city[20];
char state[2];
char zip[10];
};
struct date {
int month;
int day;
int year;
};
struct user {
char login[20];
char fullname[100];
char password[30];
struct address physical_address;
struct date birthday;
int user_type;
union {
struct {
double salary;
char *clearance;
} admin;
struct {
date donationdate[2];
double amount[2];
} donor;
struct {
double wage;
date datehired;
} worker;
} userinfo;
};
struct users[200];
If the users begins at a memory address 1000, what are the starting addresses (in bytes) of each of the following:
a) users[10]
b) users[15].physical_address.street
c) users[20].birthday.year
d) users[20].userinfo.donor.amount[1]
Solutions:
a) 4380
b) 6220
c) 8050
d) 8009