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.

SARANYA said:   7 years ago
What is the meaning for atkt, here?

Nikhitha said:   7 years ago
What is the meaning of atkt, here?

Bhavani said:   6 years ago
If we mentioned as enum starts with 1, it will starts with 1 only. Otherwise, automatically it will starts with 0.

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

Risha said:   6 years ago
Here status is a variable name as like arr in the given example:
Int arr[10,20,30]

And in enum status{pass,fail,atkt} ,value assign to staus is in the form of array so index starts from 0,1,2,......

While in the statement:-
enum status stud1,stud2,stud3

Here stud1,stud2,stud3 all are as value which is assign to the variable name status, but these are not in the form of array, we can understand these as like

enum status stud1
enum status stud2
enum status stud3

Now when we access the value of staus of array that are pass, fail, atkt
then we assign these as like stud1=pass, stud2=atkt,stud3=fail
After executing this program output will be as
0,2,1
(1)

Sushmita said:   4 years ago
What is the meaning of atkt ?

Please explain to me.
(4)

Ameya said:   2 years ago
Atkt ----> Allowed to keep terms.
(1)


Post your comments here:

Your comments will be displayed after verification.