什么是C'#'操作? [英] What is '#' operator in C?

查看:145
本文介绍了什么是C'#'操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在C'#'操作?

如果是,则在code

 枚举{ALPS,安第斯山脉,HIMALYAS};

会是什么样以下的回报?

  #ALPS


解决方案

C语言不具有运营商,但pre-处理器(中程序处理的#include 的#define )一样。在pre-处理器简单的品牌 #ALPS 成字符串ALPS

不过,这种字符串运算符只能在的#define pre处理器指令中使用。例如:

 的#define MAKE_STRING_OF_IDENTIFIER(X)#X
阿尔卑斯山的char [] = MAKE_STRING_OF_IDENTIFIER(ALPS);

在pre-处理器将上面的例子转换为以下内容:

 阿尔卑斯山的char [] =阿尔卑斯

Is there a '#' operator in C ?

If yes then in the code

enum {ALPS, ANDES, HIMALYAS};

what would the following return ?

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

这篇关于什么是C'#'操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆