10

Enumerations

  1. #include <stdio.h>
  2.  
  3. main() {
  4.     enum boolean {false, true} yes = true, no = false;
  5.  
  6.     const int FALSE = 0, TRUE = !FALSE;
  7.  
  8.     printf("false=%d\n", false);
  9.     printf("true=%d\n", true);
  10.  
  11.     printf("yes=%d\n", yes);
  12.     printf("no=%d\n", no);
  13.  
  14.     printf( yes == no ? "What?\n" : "Ok\n" );
  15.  
  16.     printf("\n");
  17.     printf("FALSE=%d\n", FALSE);
  18.     printf("TRUE=%d\n", TRUE);
  19. }
$ gcc -o enum enum.c
$ ./enum
false=0
true=1
yes=1
no=0
Ok

FALSE=0
TRUE=1

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].