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

consider the lines of code below. Indicate which are invalid, meaing either that

ID: 3620485 • Letter: C

Question

consider the lines of code below. Indicate which are invalid, meaing either that they would not compile or that they may produce a memory fault. consider each line independently of all others.

struct passport {
char last[10];
int number;
float fees;
double *country_code;
};
struct passport list[3],*passenger;
char who[7],a,*b;
double *d,d2;

b="Hello';
list->country_code=277;
list[0].country_code=d;
list[2].country_code=&d2;
*(list[3].country_code)=277;
passport.country_code=463;
passenger=&passport;
who[6]='a';
a=5;
b=&(list[0].last[5]);
passenger=&list;
passenger=&(list[0]);list[2]=(*passenger);
list[0].fees="world";
list[0].fees='p'+0.65;
*(passenger->country_code)=*d=(double)(list[0].last[12]);

Explanation / Answer

(b="Hello";) This is fine. (list->country_code=277)ERROR, country code is a pointer. must dereferance country code before assigning it a value. (List[0].country_code=&d2;) This is fine (*list[3].country_code)=277;) This is fine (passport.country_code=463;) ERROR, replace passport with list[x] or passenger (passenger=&passport;) ERROR, theres alot wrong with this one. mainly &passport. (who[6]='a';) This is fine (a=5;) ERROR, a is char (b=&(list[0].last[5]);) This is fine. (passenger=&list;) ERROR, fix by writing passenter=&list[x] (passenger=&(list[0]);list[2]=(*passenger);) These are both fine (list[0].fees="world";) ERROR, fees is a float not a char * (list[0].fees='p'+0.65;) This is fine since compiler will convert 'p' to int (*(passenger->country_code)=*d=(double)(list[0].last[12]);) ERROR, last is char not double. Hope that helps