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

In C D Question 6 1 pts typedef struct char fname [30]; char lname30]; } Student

ID: 3873646 • Letter: I

Question

In C

D Question 6 1 pts typedef struct char fname [30]; char lname30]; } Student; typedef struct { int num; char name [30]; Student stud[50]; } Course; Assume var has been assigned the address of a course structure. Course *var = malloc(sizeof(Course)) Accessing the variable fname of first student can be correctly implemented by: 1. (*(*var). stud).fname 2. (var->stud[0]).fname 3. *var. *var.fname 4. var-stud. fname * 5. (*var-stud).fname 0 1, 2 and 3 0 1, 2 and 5 o 2 and 5 o 2 only o 2, 3 and 4

Explanation / Answer

Correct answer :  2 only. (var->stud[0].fname)

1) To access fname from an object (stud) of student struct we need to write (stud.fname). Since it's an array of student objects, we have to specify proper index that we want to access, hence, (stud[0].fname) (for the first student).

2)Now this stud object is a member of course sturcture and a pointer var is pointing to one instance of this structure. So, to access any member of course structure using a pointer, we write (var->stud[0].fname)