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:
58 comments Page 3 of 6.
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:
8 years ago
Why are we getting sequence 2 after sequence 0?
SARANYA said:
8 years ago
What is the meaning for atkt, here?
Nikhitha said:
8 years ago
What is the meaning of atkt, here?
Bhavani said:
7 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:
7 years ago
In this enum is a data type how can we mention? here it starts with 1or0.
Vivek bhaskar said:
1 month ago
Nice explanation. Thanks all.
Shafi said:
1 decade ago
What is the need of stud1,stud2, stud3 declared as enum type ?
declaration of stud1,stud2, stud3 as int type is Ok. it will made to confuse.
declaration of stud1,stud2, stud3 as int type is Ok. it will made to confuse.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers