421,038 views
33 votes
33 votes
Suppose we define a WaitlistEntry as follows:

typedef struct{
int iPriority; /* Priority of the student to be enrolled */
int iStudentID; /* ID of the student */
}
WaitlistEntry;

Below are different implements of a function to create a WaitlistEntry from given iPriority and iStudentID data. Some of these implementations are flawed. Identify them and describe what is wrong with them briefly:

WaitlistEntry createWL( int iPriority, int iStudentlD )
WaitlistEntry w,
w.iPriority iPriority;
w.iStudentlD iStudentlD;
return w;

a. correct
b. incorrect, leaks memory
c. incorrect, syntax error
d. incorrect, data will be overwritten by next function call

User Isurujay
by
2.8k points

1 Answer

15 votes
15 votes

Answer:

You have syntax errors, but I don't know if it happened when you posted this question, nevertheless

Step-by-step explanation:

Correct code:

WaitlistEntry createWL( int iPriority, int iStudentID ) { // Opening Brace

WaitlistEntry w; // Should be ; not ,

w.iPriority = iPriority; // Assign Missing

w.iStudentID = iStudentID; // Assign Missing

return w;

} // Closing Brace

// Also note: iStudentID this actually has an 'l' which is LD. Not ID, this is why I assume these errors happened when posting the question.

User Yanefedor
by
2.2k points