Enums (C)

enum.c

#include <stdio.h>

/* We usually use _t for enum names */
/* By default, A would get the zero value and the others
 * would get a value incremented by one as we go through.
 * B would get the value of 1, C of 2 and so on. We can
 * set the value to start "counting" by assigning it to
 * the A.                           */

typedef enum {A = 1, B, C, D, E} alphabet_t;

int main(void)
{
     alphabet_t test = B;

     if(test == 2)
        printf("ok\n");

     return 0;
}

This code was developed by me, G. Samaras.

Have questions about this code? Comments? Did you find a bug? Let me know! 😀
Page created by G. (George) Samaras (DIT)

One thought on “Enums (C)

  1. Pingback: character converter

Leave a comment