What is '#' operator in C?

前端 未结 5 498
夕颜
夕颜 2020-12-11 12:19

Is there a \'#\' operator in C ?

If yes then in the code

enum {ALPS, ANDES, HIMALYAS};

what would the following return ?

相关标签:
5条回答
  • 2020-12-11 12:29

    "#" isn't an operator in C. But The preprocessor (which operates before the compiler) provides the ability for _ the inclusion of header files : enter code here#include _ macro expansions : **#define foo(x) bar x** _ conditional compilation :

    **#if DLEVEL > 5
        #define STACK   200
    #else
       #define STACK   50
        #endif
    #endif**
    

    In enum {ALPS, ANDES, HIMALYAS}; Nothing would return ALPS. You've just defined a strong integer type (ALPS = 0, ANDES = 1 and HIMALYAS = 2), but it's useles without a name to this enumreation like this : enum mountain {ALPS, ANDES, HIMALYAS};

    0 讨论(0)
  • 2020-12-11 12:30

    No. # is used for preprocessor directives, such as #include and #define. It can also be used inside macro definitions to prevent macro expansion.

    0 讨论(0)
  • 2020-12-11 12:34

    The C language does not have an # operator, but the pre-processor (the program that handles #include and #define) does. The pre-processor simple makes #ALPS into the string "ALPS".

    However, this "stringify" operator can only be used in the #define pre-processor directive. For example:

    #define MAKE_STRING_OF_IDENTIFIER(x)  #x
    char alps[] = MAKE_STRING_OF_IDENTIFIER(ALPS);
    

    The pre-processor will convert the above example into the following:

    char alps[] = "ALPS";
    
    0 讨论(0)
  • 2020-12-11 12:46

    There is no # operator in C. The # prefix is used to delineate preprocessor instructions.

    See: http://en.wikipedia.org/wiki/C_preprocessor

    0 讨论(0)
  • 2020-12-11 12:53

    The sharp symbol in C is the prefix for the preprocessor directives.

    It is not an operator ...

    0 讨论(0)
提交回复
热议问题