0
#include<stdio.h>
#include<conio.h>
main()
{
 typedef enum y;
 int c;
 y colour {RED,WHITE,BLUE,BLACK};
 clrscr();
 printf("The assigned value is %d\n",RED);
 printf("The assigned value is %d\n",BLUE);
 printf("The assigned value is %d\n",BLACK);
 c=RED+BLACK;
 printf("RED+BLACK IS %d",c);

 getch();
}

What is wrong with this code please?

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Daita
0

>typedef enum y;
The enum keyword is only part of a type, while typedef may accept this line, you can't subsequently use y in place of enum. Though that effect can be created with #define:

#include<stdio.h>

int main(void)
{
#define y enum
    int c;
    y colour {RED,WHITE,BLUE,BLACK};

    printf("The assigned value is %d\n", RED);
    printf("The assigned value is %d\n", BLUE);
    printf("The assigned value is %d\n", BLACK);
    c = RED + BLACK;
    printf("RED+BLACK IS %d\n", c);

    return 0;
#undef y
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.