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

Given the following two variables, which of the accesses below are valid? Phoneb

ID: 3660541 • Letter: G

Question

Given the following two variables, which of the accesses below are valid?

Phonebook pbook;

Phonebook *ptr = &pbook;

For example, pbook.name is a valid access, but pbook->name is invalid.

i. pbook.phones

ii. ptr.phones

iii. ptr->names

iv. ptr->names[0]

v. ptr->names[0][1]

vi. ptr->phones[0].area_code

vii. ptr->phones[0]->four_digits

viii. ptr->phones[0]->names

ix. (*ptr).phones[0]


The structure is:

#define MAX_LENGTH 80

#define MAX_NUMBER_OF_PHONES 10

typedef struct phone {

int area_code;

int three_digits;

int four_digits;

} Phone;

typedef struct phonebook {

char names[MAX_NUMBER_OF_PHONES][MAX_LENGTH + 1];

Phone phones[MAX_NUMBER_OF_PHONES];

int number_of_phones;

} Phonebook;

Explanation / Answer

ptr->phones[0]->names ptr->phones[0].area_code

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote