请教const,static和const static的问题
请详细解答一下下面的题,本人是菜鸟,越详细越好,谢谢
Fill the blanks inside class definition
Class Test
{
public:
_____ int a;
_____ int b;
public:
Test::Test(int _a, int _b):a(_a)
{
b = _b;
}
};
int Test::b;
int _tmain(int argc, _TCHAR * argv[])
{
Test t1(0, 0), t2(1, 1);
t1.b = 10;
t2.b = 20;
printf("%u %u %u %u", t1.a ,t1.b ,t2.a, t2.b);
return 0;
}
Running result: 0 20 1 20
A. static/const
B. const/static
C. --/static
D.const static/static
E. None of the above
Answer:BC
Fill the blanks inside class definition
Class Test
{
public:
_____ int a;
_____ int b;
public:
Test::Test(int _a, int _b):a(_a)
{
b = _b;
}
};
int Test::b;
int _tmain(int argc, _TCHAR * argv[])
{
Test t1(0, 0), t2(1, 1);
t1.b = 10;
t2.b = 20;
printf("%u %u %u %u", t1.a ,t1.b ,t2.a, t2.b);
return 0;
}
Running result: 0 20 1 20
A. static/const
B. const/static
C. --/static
D.const static/static
E. None of the above
Answer:BC
...全文
相关推荐
iOS开发中关键字const/static/extern、UIKIT_EXTERN的区别和用法
主要介绍了iOS 关键字const/static/extern、UIKIT_EXTERN区别和用法,需要的朋友可以参考下
C语言中auto register static const volatile 区别
C语言中auto register static const volatile 区别
static与const区别[项目源码]
本文详细介绍了static和const在编程中的作用与区别。static主要用于修饰局部变量、全局变量和函数,通过改变变量的存储位置(从栈区到静态区)来延长其生命周期或限制其作用域。const则用于定义常量,确保变量的值在初始化后不可被修改,常用于修饰常变量、静态字符串和函数参数,以防止意外修改。文章通过具体代码示例和内存区域分析,清晰地展示了二者的核心差异,帮助读者深入理解其应用场景和底层原理。
C++中const与static用法详解[项目源码]
本文详细介绍了C++中const和static关键字的用法。const主要用于限制变量或对象的可修改性,包括修饰普通变量、指针、函数、类成员和对象,确保代码的安全性。static则用于改变变量或函数的存储周期和作用域,包括修饰全局变量、局部变量和类成员,实现数据的共享和全局唯一性。文章还探讨了const与static的结合应用,特别是在类内静态常量的初始化中的使用,并提供了常见的避坑指南。通过实例代码和详细解释,帮助读者深入理解这两个关键字的灵活用法和核心概念。
const与static用法完整总结
const与static在编程中经常用到,并且很重要, 这里就把他们的用法总结,希望对大家有帮助


