MAH-CET 2025 Computer PYQ — What will be the ouput of the following C function? #include <std… | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
MAH-CET 2025 — Computer PYQ
MAH-CET | Computer | 2025
What will be the ouput of the following C function? #include <stdio.h> enum birds {SPARROW, PEACOCK, PARROT}; enum animals {TIGER = 8, LION, RABBIT, ZEBRA}; int main() { enum birds m = TIGER; int k; k = m; printf ("%d\n" , k); return 0; }
Choose the correct answer:
A.
0
B.
Compile time error
C.
1
D.
8
(Correct Answer)
Correct Answer:
8
Explanation
Logic
Enumeration birds: Since no values are specified, they are assigned starting from 0:
SPARROW=0,PEACOCK=1,PARROT=2
Enumeration animals: Here, TIGER is explicitly initialized to 8. The following members increment automatically:
TIGER=8,LION=9,RABBIT=10,ZEBRA=11
Variable Assignment: The code assigns TIGER (which is 8) to the variable m. Even though m is of type enum birds, C allows this integer assignment.
m=TIGER⟹m=8
Final Output: The integer k takes the value of m, and printf displays it.
k=m⟹k=8
Solution
The calculation of the output is represented as:
Value of TIGER=8
Assignment: m=TIGER⟹m=8
Assignment: k=m⟹k=8
Output=printf("%d", k)⟹8
Final Answer:
The output of the program is 8.
Explanation
Logic
Enumeration birds: Since no values are specified, they are assigned starting from 0:
SPARROW=0,PEACOCK=1,PARROT=2
Enumeration animals: Here, TIGER is explicitly initialized to 8. The following members increment automatically:
TIGER=8,LION=9,RABBIT=10,ZEBRA=11
Variable Assignment: The code assigns TIGER (which is 8) to the variable m. Even though m is of type enum birds, C allows this integer assignment.
m=TIGER⟹m=8
Final Output: The integer k takes the value of m, and printf displays it.