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:
56 comments Page 1 of 6.

Sushmita said:   1 year ago
What is the meaning of atkt ?

Please explain to me.
(1)

Risha said:   4 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

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

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

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

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

Archana said:   5 years ago
@Subrato.

In enum data type, by default it gives the value 0 to the first variable ,1 to the second variable and so on.

So, here we have values, pass=0,fail=1 and atkt=2.
By assigning these values to stud1 ,stud2 and stud3 we get;
Stud1= pass (which has value 0).
Stud2=atkt (which has value 2),
Stud3=fail(which has value 1),
By printing the variables we get 021.

Subrato said:   5 years ago
Why are we getting sequence 2 after sequence 0?

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

Piyush said:   5 years ago
Can you help me?

Display a number which last and first two digits are divided with 11 and that number should be the square of a number?

Generate the output of this program and program also.


Post your comments here:

Your comments will be displayed after verification.