C / C ++中的enum vs. const vs.#define
在这里,我们将看到C或C++程序中的enum,const和#define之间有什么区别。当我们必须决定选择它们时,这三者会造成一些混乱。现在让我们看看这三件事是什么。
const或静态const
const是常量类型数据,或者staticconst是常量,但存储说明符是静态的。因此它将保持活动状态,直到程序终止,并且常量类型数据无法更新。
示例
#include <iostream>
using namespace std;
main() {
int x;
x = 65700;
cout << "x is (as integer):" << x << endl;
x = (short)65700; //will be rounded after 2-bytes
cout << "x is (as short):" << x << endl;
}输出结果
x is (as integer):65700 x is (as short):164
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短