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:
57 comments Page 5 of 6.
Nithya said:
9 years ago
Here, what is meant by status?
Virendrasinh chauhan said:
8 years ago
enum status { pass, fail, atkt}; {pass=0,fail=1,atkt=2}////// here enum status is a user define data type.
enum status stud1, stud2, stud3; ////////that's the reason we require the same user define data type for storing the result.
stud1 = pass; //// 0
stud2 = atkt; //// 2
stud3 = fail; //// 1
enum status stud1, stud2, stud3; ////////that's the reason we require the same user define data type for storing the result.
stud1 = pass; //// 0
stud2 = atkt; //// 2
stud3 = fail; //// 1
TUKARAM said:
8 years ago
YES, ENUM START WITH 0.
Navya said:
8 years ago
Why are use std?
Ratna Priya said:
8 years ago
Here we are also taken as pass=1, fail=2,atkt=3.
Stud1=pass;///1
Stud2=atkt;///3
Stud3=fail;///2.
Then option D is also correct.
Can anyone explain this to me?
Stud1=pass;///1
Stud2=atkt;///3
Stud3=fail;///2.
Then option D is also correct.
Can anyone explain this to me?
(2)
Sindhu said:
8 years ago
Enum like array by default starts with 0, So according to that 0,2,1 is the answer.
Piyush said:
8 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.
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.
Silpa said:
8 years ago
Please tell me anyone. Here what is the meaning of atkt?
Subrato said:
7 years ago
Why are we getting sequence 2 after sequence 0?
Archana said:
7 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.
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.
(2)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers