C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 1)
1.
What is the output of the program given below ?
#include<stdio.h>
int main()
{
enum status { pass, fail, atkt};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = atkt;
stud3 = fail;
printf("%d, %d, %d\n", stud1, stud2, stud3);
return 0;
}
Answer: Option
Explanation:
enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2
stud1 = pass (value is 0)
stud2 = atkt (value is 2)
stud3 = fail (value is 1)
Hence it prints 0, 2, 1
Discussion:
57 comments Page 6 of 6.
Pradeep Bhat said:
1 decade ago
I agree with shafi. int can do the work of enum declaration here.
Akram Regard said:
1 decade ago
We know that enum start with 0, 1, 2.
Here we are seeing that at enum's 0th position we have pass so it assign value 0 and atkt at number 2th so we are getting 2 after 0 and last we have fail is 1th position so we got 1 as last.
Here we are seeing that at enum's 0th position we have pass so it assign value 0 and atkt at number 2th so we are getting 2 after 0 and last we have fail is 1th position so we got 1 as last.
Lipsha said:
1 decade ago
What is status here for?
Nikhil said:
1 decade ago
What is enum please explain in brief?
Asaduzzzaman kanok said:
1 decade ago
If enum takes the format like {1, 2, 3....}.
So pass =1, fail = 2, atkt = 3.
I think then output will be (123).
So pass =1, fail = 2, atkt = 3.
I think then output will be (123).
Sivaraman said:
1 decade ago
Will enum operated state on 0? I confused.
Shivesh said:
1 decade ago
This coding throws error in gcc compiler.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers