What is '#' operator in C?

妖精的绣舞 提交于 2019-11-27 07:21:42

问题


Is there a '#' operator in C ?

If yes then in the code

enum {ALPS, ANDES, HIMALYAS};

what would the following return ?

 #ALPS 

回答1:


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



回答2:


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

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




回答3:


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




回答4:


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

It is not an operator ...




回答5:


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



来源:https://stackoverflow.com/questions/7952903/what-is-operator-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!