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.
Deepak said:
8 years ago
Is there any run time, compile error in this program? Can anyone tell me?
Naty said:
7 years ago
Thanks for the explanation @XYZ.
Keerthana said:
7 years ago
Since enum members are not pre-assigned,they will be assigned with 0,1,2 by default. So as a result pass=0,fail=1,absent=2
stud1=pass=0,
stud2=absent=2,
stud3=fail=1
Hence the output:0 2 1.
stud1=pass=0,
stud2=absent=2,
stud3=fail=1
Hence the output:0 2 1.
Jayshri said:
7 years ago
Thank you all.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers