enum

Enumerated data types.

 

Used to define a list of integer constants.

 

#include <stdio.h>
enum riders {Lorenzo, Pedrosa, Stoner, Rossi} ;

int main( )
{
	printf("Stoner is at position %d \n", Stoner) ;

   return 0;
}

Compile & run:

Stoner is at position 2

 

Like arrays, the first position starts from ZERO.

 

Other integer values can be assigned:

#include <stdio.h>
enum riders {Lorenzo = 7, Pedrosa = 63, Stoner = 6, Rossi = 10} ;

int main( )
{
	printf("Pedrosa has an integer value of %d \n", Pedrosa) ;

   return 0;
}

Compile & run:

Pedrosa has an integer value of 63

 

 

If left unitialised each would have a unique value.

Leave a Reply