Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to use typedef to declare and use enum in C

3 Answers

0 votes
#include <stdio.h>

typedef enum 
{ 
   Zero,
   One, 
   Two, 
} numbers;

int main(void)
{
    numbers n = One;
    
    printf("n = %d\n", n);
        
    return 0;
}

   
/*
run:
 
n = 1

*/

 



answered Aug 29, 2017 by avibootz
0 votes
#include <stdio.h>

enum numbers
{ 
   Zero,
   One, 
   Two, 
};

typedef enum numbers numbers;

int main(void)
{
    numbers n = One;
    
    printf("n = %d\n", n);
        
    return 0;
}

   
/*
run:
 
n = 1

*/

 



answered Aug 29, 2017 by avibootz
0 votes
#include <stdio.h>

enum numbers
{ 
   Zero,
   One, 
   Two, 
};

typedef enum numbers numbers;

int main(void)
{
    numbers n = One;
    
    if (n == Zero)
    {
        puts("Zero");
    }
    else if (n == One)
    {
        puts("One");    
    }
    else if (n == Two)
    {
        puts("Two");
    }
        
    return 0;
}

   
/*
run:
 
One

*/

 



answered Aug 29, 2017 by avibootz

Related questions

1 answer 123 views
123 views asked May 7, 2021 by avibootz
1 answer 139 views
1 answer 147 views
147 views asked Dec 29, 2021 by avibootz
2 answers 216 views
216 views asked Aug 18, 2017 by avibootz
2 answers 167 views
167 views asked Aug 18, 2017 by avibootz
1 answer 202 views
...