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 3 of 6.
Navya said:
8 years ago
Why are use std?
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:
7 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?
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.
JITIN JINDAL said:
1 decade ago
It is not necessary that enum types will always start from 0 and so on we can change it as enum xyz{A=2,B,C,Y=9,Z,J,K=11,M};
Here as A is declared with 2 so now B has index 3 n C has index 4 now see we have given Y with an index of 9 so Z and J will be indexed as 10 n 11 respectively and K will also share the same index as 11 and has index 12.
Here as A is declared with 2 so now B has index 3 n C has index 4 now see we have given Y with an index of 9 so Z and J will be indexed as 10 n 11 respectively and K will also share the same index as 11 and has index 12.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers