What is '#' operator in C?

2019-02-20 03:06发布

Is there a '#' operator in C ?

If yes then in the code

enum {ALPS, ANDES, HIMALYAS};

what would the following return ?

 #ALPS 

5条回答
疯言疯语
2楼-- · 2019-02-20 03:06

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

查看更多
走好不送
3楼-- · 2019-02-20 03:22

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";
查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-02-20 03:26

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

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

查看更多
再贱就再见
5楼-- · 2019-02-20 03:26

"#" 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};

查看更多
甜甜的少女心
6楼-- · 2019-02-20 03:33

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

It is not an operator ...

查看更多
登录 后发表回答