C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 6)
6.
What will be the output of the program ?
#include<stdio.h>
int main()
{
enum status {pass, fail, absent};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = absent;
stud3 = fail;
printf("%d %d %d\n", stud1, stud2, stud3);
return 0;
}
Discussion:
24 comments Page 3 of 3.
Priya said:
1 decade ago
How it assigning the value 0 for pass 2 for absent and 1 for fail. Wats the logic behind this? Please tell me in detail.
Sundar said:
2 decades ago
Hi Ranjith,
Kindly read the program very carefully.
The order of values assigned are
stud1 = pass; // here pass = 0
stud2 = absent; // here absent = 2
stud3 = fail; // here fail = 1
So,
printf("%d %d %d\n", stud1, stud2, stud3);
produces the output as 0, 2, 1.
Hope you understand. Have a nice day!
Kindly read the program very carefully.
The order of values assigned are
stud1 = pass; // here pass = 0
stud2 = absent; // here absent = 2
stud3 = fail; // here fail = 1
So,
printf("%d %d %d\n", stud1, stud2, stud3);
produces the output as 0, 2, 1.
Hope you understand. Have a nice day!
Ranjith said:
2 decades ago
Know that enum values are initialising from 0 only how it would get 2 and 1
Krishna said:
2 decades ago
Because enum values are initialised from zero.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers