Macro definition:
There are three benefits to using a string instead of a data at the beginning of the code
1. Make some data meaningful
#define KOUT-1
#define Kappsecret KDJGHHGF
#define Kappkey 123456
2, easy to use, similar to the meaning of the restrained function
#define KADD (a B) ((a) + (b))
#define Kmultiple (A, a) ((a) * (b))
3, the output log switch
#if 1
#define DEBUG (x) printf ("%s\n", X)
#else
#define DEBUG (x)
#endif
Enumeration:
1, define an enumeration, the type name is Kanimalcategory
typedef enum{
Kanimalcategoryburu = 2,//Default starting from 0
Kanimalcategorymaoke = 5,//The latter will add 1 above the former, if not assigned
Kanimalcategoryfeiqin = 7,//
Kanimalcategoryzoushou//8
2. Differences between macro definitions and enumerations
A macro definition is a value/expression, not a type
An enumeration is a type that can define a variable of an enumeration type
Macro definitions and Enumerations