I understand that the last line should be \" q.c = \'4\'; \" However I am unsure
ID: 3536515 • Letter: I
Question
I understand that the last line should be " q.c = '4'; " However I am unsure of how to fix the second to last line.
q.ptr can't be assigned the value of 7 as it is a pointer. But I don't know how to assign it to an int variable if we're not allowed to declare one. Any ideas?
Correct the errors. Do not declare any other variables or change any variable names or data types. All structure members must be assigned values.
struct quest
{
int * ptr;
char c;
};
// elsewhere in the program
quest q;
q.ptr = 7;
q.c = "4";
Explanation / Answer
The pointer needs to be deferenced, q.ptr is suppose to hold an address. If you wish to change the value of q.ptr then it should be *(q.ptr) = 7; The reason for the parenthesis is because of precedence.