Macro definitions and Enumerations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.