C Programming - Typedef - Discussion
Discussion Forum : Typedef - Find Output of Program (Q.No. 1)
1.
What will be the output of the program?
#include<stdio.h>
int main()
{
enum color{red, green, blue};
typedef enum color mycolor;
mycolor m = red;
printf("%d", m);
return 0;
}
Discussion:
12 comments Page 1 of 2.
Harshini said:
7 years ago
Here enum is same as an array but it considers only the integer values.
Noobie said:
8 years ago
How to print red in this program? Can anyone explain it?
Vikas chaturvedi said:
10 years ago
enum color {red,green, blue};
red=0.
green=1.
blue=2.
Because printf("%d",m);
It always print a integer value if we talk about red then it will print 0, if we talk about green then it will be print 1 similarly for blue it will print 2.
red=0.
green=1.
blue=2.
Because printf("%d",m);
It always print a integer value if we talk about red then it will print 0, if we talk about green then it will be print 1 similarly for blue it will print 2.
(1)
Sam said:
1 decade ago
#include<stdio.h>
int main()
{
enum color{red, green, blue};/*red=0,green=1,blue=2 compiler automatically assigns*/
typedef enum color mycolor;//creating alias name to datatype
mycolor m = red;/* typedef int integer;
printf("%d", m); integer i=0;(here integer acts as int)
return 0; */
}
int main()
{
enum color{red, green, blue};/*red=0,green=1,blue=2 compiler automatically assigns*/
typedef enum color mycolor;//creating alias name to datatype
mycolor m = red;/* typedef int integer;
printf("%d", m); integer i=0;(here integer acts as int)
return 0; */
}
(1)
Manish Rinwa said:
1 decade ago
This will print the position of array[0]and starts from zero automatically.
Neeraj said:
1 decade ago
@Parin.
We can't print red, green and blue using printf() , we have to use switch case for that.
We can't print red, green and blue using printf() , we have to use switch case for that.
Parin said:
1 decade ago
What should I write in printf in order to get output the actual value of enum?
Siddu said:
1 decade ago
enum color mycolor makes mycolor as a data type and its same as "enum color". When we create a variable of mycolor by "mycolor m" it creates variable of "enum color" and assigned with "red". Here red is a named constant and the value of the red is 0 by default.So when we print m it prints 0.
Piyush bansal said:
1 decade ago
This will print the position of array[0] and enum color is array here so print '0'.
Elakkiya said:
1 decade ago
enum value starts from zero automatically.so only it print the value as 0
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers