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 2 of 6.
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.
Sindhu said:
8 years ago
Enum like array by default starts with 0, So according to that 0,2,1 is the answer.
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)
Navya said:
8 years ago
Why are use std?
TUKARAM said:
8 years ago
YES, ENUM START WITH 0.
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
Nithya said:
8 years ago
Here, what is meant by status?
Mamun Rahaman said:
9 years ago
Thanks for all your kind information.
Puja said:
9 years ago
When I run this program then it produces the output only 0, 2 not 1. Why?
HARIPRASATH PANNEERSELAVAM said:
9 years ago
@RamKrishnan - Thanks for your kind information.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers