118k views
3 votes
Complete change grade() to output if gradepointer is null or assign gradevalue to the variable pointed by gradepointer.

a. If gradepointer is null
b. Assign gradevalue
c. End with a newline
d. None of the above3

1 Answer

4 votes

Final answer:

To complete the change_grade() function, you need to check if gradepointer is null and, if so, assign the value of gradevalue to the variable pointed by gradepointer.

Step-by-step explanation:

To complete the change_grade() function, you need to check if gradepointer is null and, if so, assign the value of gradevalue to the variable pointed by gradepointer. Here's an example:

void change_grade(int *gradepointer, int gradevalue) {
if (gradepointer == nullptr) {
gradepointer = &gradevalue;
}
}

This code checks if gradepointer is null using the nullptr keyword, and if so, assigns the value of gradevalue to gradepointer by using the address-of operator (&). The function should end with a newline character, but since this is a simple function implementation, there is no need to explicitly add it.

User Lagoon
by
7.4k points