Multiple choice technology programming languages

The following code will generate a compiler error.

string GetAgePhrase(int age) {
    if (age > 60) return "Senior";
    if (age > 40) return "Middle-aged";
    if (age > 20) return "Adult";
    if (age > 12) return "Teen-aged";
    if (age > 4) return "Toddler";
}

Which of the following statements, inserted as the last line of the function, would solve the problem?

  1. a. continue;

  2. b. break;

  3. c. return "Infant";

  4. d. return 0;

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The function declares a string return type but has no return statement for ages 4 and below. Adding 'return "Infant";' as the last line ensures all execution paths return a string, satisfying the compiler's requirement that non-void functions must return a value on all paths.