什么是“#” C 中的运算符?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
C 语言没有
#
运算符,但预处理器(处理#include
和#define
的程序)有。预处理器简单地将#ALPS
转换为字符串"ALPS"
。但是,此“stringify”运算符只能在
#define
预处理器指令中使用。例如:预处理器会将上面的示例转换为以下内容:
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:The pre-processor will convert the above example into the following:
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
不可以。
#
用于预处理器指令,例如#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.C 中的尖符号是预处理器指令的前缀。
这不是运营商...
The sharp symbol in C is the prefix for the preprocessor directives.
It is not an operator ...
“#”在 C 中不是运算符。
但是预处理器(在编译器之前运行)提供了以下能力:
_ 包含头文件:
在此处输入代码
#include_ 宏扩展:
**#define foo(x) bar x**
_ 条件编译:
在
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 :
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};