#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?

Recommended Answers

Probably doesn't work.

You're supposed to tell us what's wrong.

Jump to Post

All 3 Replies

Probably doesn't work.

You're supposed to tell us what's wrong.

>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
}

Thank you very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.