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;
}
0, 1, 2
1, 2, 3
0, 2, 1
1, 3, 2
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 3 of 6.

Mounika said:   9 years ago
How it is 0, 2, 1? Where we are declared with 0, 1, 2. So output should be 0, 1, 2.

Sonu said:   1 decade ago
But while declaring the sequence is ok but in the output why the sequence change ?

Vinod said:   10 years ago
enum status stud1, stud2, stud3;

Can anyone explain this declaration statement?

Anita said:   6 years ago
In this enum is a data type how can we mention? here it starts with 1or0.

Puja said:   9 years ago
When I run this program then it produces the output only 0, 2 not 1. Why?

Pradeep Bhat said:   1 decade ago
I agree with shafi. int can do the work of enum declaration here.

Prema said:   9 years ago
If enum takes value staring from 1 then the output will be D.

Silpa said:   8 years ago
Please tell me anyone. Here what is the meaning of atkt?

Mukund said:   1 decade ago
Well I cant understand this program can anyone help.

Tejas said:   1 decade ago
Please anyone explain me about enumerated data type.


Post your comments here:

Your comments will be displayed after verification.