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:
58 comments Page 6 of 6.
Purnima said:
1 decade ago
YES as we know that the array begins with a[0], like this only the in enum it is initialized to 0 first.
Am I correct? Please say if anything wrong.
Am I correct? Please say if anything wrong.
Nagesh said:
1 decade ago
Explanation given by Ram krushna is correct and by the way jeevan enum's syntax is like this that's why it start from 0
Jeevan said:
1 decade ago
Well they start with 0 not 1 ?
Swetha said:
1 decade ago
Answer may be option D also. Why it is option C only? Can you explain in depth please.
Mani krishna said:
1 decade ago
Ram krishna you are correct.
Ram krishna said:
1 decade ago
Here enum is enumerated data type.
It will give sequential no's to variables declared in braces in program pass=0, fail=1, atkt=2.
Hence they are assigned to std1, std2, std3.
See the sequence in printf statement then determine the answer.
It will give sequential no's to variables declared in braces in program pass=0, fail=1, atkt=2.
Hence they are assigned to std1, std2, std3.
See the sequence in printf statement then determine the answer.
Mukund said:
1 decade ago
Well I cant understand this program can anyone help.
Adesh said:
2 decades ago
Whats the use of enum here?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers