什么是用C宏常量和常变量之间的区别? [英] What is the difference between macro constants and constant variables in C?

查看:430
本文介绍了什么是用C宏常量和常变量之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
   href=\"http://stackoverflow.com/questions/1674032\">静态常量与#定义

Possible Duplicate:
"static const" vs "#define" in C

我开始学习C,无法清楚地了解宏和常变量之间的区别。

I started to learn C and couldn't understand clearly the differences between macros and constant variables.

当我写什么样的变化,

#define A 8

const int A = 8

推荐答案

宏由pre处理器处理 - 在pre-处理器做文本替换在源文件中,替换A的所有出现字面8。

Macros are handled by the pre-processor - the pre-processor does text replacement in your source file, replacing all occurances of 'A' with the literal 8.

常量由编译器处理。他们有类型安全的好处。

Constants are handled by the compiler. They have the added benefit of type safety.

有关的实际编$ C $℃,用任何现代编译器,应该有在两者之间的零的性能差异。

For the actual compiled code, with any modern compiler, there should be zero performance difference between the two.

这篇关于什么是用C宏常量和常变量之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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