Enum fruit_tag {
BLUEBERRY,
BANANA,
PINEAPPLE,
WATERMELON
};
typedef enum fruit_tag fruit_t;
void printFruit(fruit_t myFruit) {
switch(myFruit) {
case BLUEBERRY:
printf("a blueberry");
break;
case BANANA:
printf("a banana");
break;
case PINEAPPLE:
printf("a pineapple");
break;
case WATERMELON:
printf("a watermelon");
break;
}
}
void compareFruit(fruit_t fruit1, fruit_t fruit2) {
if (fruit1 > fruit2) {
printFruit(fruit1);
printf(" is larger than ");
printFruit(fruit2);
}
else {
printFruit(fruit1);
printf(" is smaller than ");
printFruit(fruit2);
}
}
int main(void) {
fruit_t myFruit = PINEAPPLE;
fruit_t otherFruit = BLUEBERRY;
compareFruit(myFruit, otherFruit);
return 0;
What is the output?

Respuesta :

Answer:

The output is "a pineapple is larger than a blueberry ".

Explanation:

In the given  C language code Enum, typedef, and two methods "printfruit and compareFruit" is declared, that can be defined as follows:

  • In the enum "fruit_tag" there are multiple fruit name is declared that use as the datatypes.
  • In the next line, the typedef is defined, that enum to define another datatype that is "fruit_t".
  • In the next step, the printFruit method is defined that accepts "myFruit" variable in its parameter and use the switch case to to check value.
  • In the "compareFruit" method, it accepts two parameters and uses the if-else block to check its parameters value and print its value.
  • In the main method,  two variable "myFruit and otherFruit" variable is declared that stores the values and pass into the "compareFruit" method and call the method.