什么是“#” C 中的运算符?

发布于 2024-12-13 01:25:25 字数 145 浏览 3 评论 0原文

C 中有“#”运算符吗?

如果是,那么在代码中

enum {ALPS, ANDES, HIMALYAS};

以下将返回什么?

 #ALPS 

Is there a '#' operator in C ?

If yes then in the code

enum {ALPS, ANDES, HIMALYAS};

what would the following return ?

 #ALPS 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

Saygoodbye 2024-12-20 01:25:25

C 语言没有# 运算符,但预处理器(处理#include#define 的程序)有。预处理器简单地将#ALPS 转换为字符串"ALPS"

但是,此“stringify”运算符只能在 #define 预处理器指令中使用。例如:

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

预处理器会将上面的示例转换为以下内容:

char alps[] = "ALPS";

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";
冰雪梦之恋 2024-12-20 01:25:25

C 中没有# 运算符。# 前缀用于描述预处理器指令。

请参阅:http://en.wikipedia.org/wiki/C_preprocessor

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

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

橘虞初梦 2024-12-20 01:25:25

不可以。# 用于预处理器指令,例如#include#define。它还可以在宏定义内部使用,以防止宏扩展。

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

梦幻之岛 2024-12-20 01:25:25

C 中的尖符号是预处理器指令的前缀。

这不是运营商...

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

It is not an operator ...

败给现实 2024-12-20 01:25:25

“#”在 C 中不是运算符。
但是预处理器(在编译器之前运行)提供了以下能力:
_ 包含头文件:
在此处输入代码#include
_ 宏扩展:**#define foo(x) bar x**
_ 条件编译:

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

enum {ALPS、ANDES、HIMALYAS} 中;
没有什么可以返回阿尔卑斯山。您刚刚定义了一个强整数类型(ALPS = 0、ANDES = 1 和 HIMALYAS = 2),但如果没有此枚举的名称,它就毫无用处,如下所示:
枚举山{阿尔卑斯山、安第斯山脉、喜马拉雅山};

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文