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 6 of 6.

Shankar said:   10 years ago
It's really nice thanks all.

Adesh said:   1 decade ago
Whats the use of enum here?

Lipsha said:   1 decade ago
What is status here for?

Mosim said:   1 decade ago
Plese explain me enump?

TUKARAM said:   8 years ago
YES, ENUM START WITH 0.

Kumar shanu said:   9 years ago
How it can possible?

Navya said:   8 years ago
Why are use std?


Post your comments here:

Your comments will be displayed after verification.