QT乱翻书-const
2021/11/7 6:09:57
本文主要是介绍QT乱翻书-const,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
跳转到大纲
QT乱翻书-const
1 #include <iostream> 2 #include <string.h> 3 4 using namespace std; 5 6 7 /* 8 C中的const可以通过指针进行修改 9 C++中的const优化: 10 1、如果以常量初始化const,编译器会将变量的值放入符号常量表 11 通过指针变量p访问空间内容*p取的是空间的值; 12 通过变量a访问的是符号常量表中的值。 13 2、如果以变量初始化const修饰的变量,没有符号常量表,立即开辟空间。 14 5、尽量用const代替#define,const有类型,const有作用域 15 16 */ 17 18 void test01() 19 { 20 const int a = 10; // 放入了符号常量表 21 int *p = (int *)&a; 22 *p = 100; 23 cout << "*p = " << *p << endl; 24 cout << "a = " << a << endl; 25 } 26 void test02() 27 { 28 int b = 100; 29 const int a = b; // 放入了符号常量表 30 int *p = (int *)&a; 31 *p = 100; 32 cout << "*p = " << *p << endl; 33 cout << "a = " << a << endl; 34 } 35 36 struct stu { 37 int num; 38 char name[32]; 39 }; 40 41 void test03() 42 { 43 stu lucy = {100, "lucy"}; 44 stu *p = (stu *)&lucy; 45 p->num = 300; 46 strcpy(p->name, "bobo"); 47 cout << p->num << ":" << p->name; 48 } 49 50 int main() 51 { 52 test01(); 53 test02(); 54 test03(); 55 return 0; 56 }
这篇关于QT乱翻书-const的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-06有没有什么开源的py项目可以对图像进行分类-icode9专业技术文章分享
- 2024-07-05feign默认connecttimeout和readtimeout是多少-icode9专业技术文章分享
- 2024-07-05idea控制台,日志太多,导致部分想看得日志被刷走 搜不到-icode9专业技术文章分享
- 2024-07-05The server selected protocol version Tls10 is not accepted by client preferences [TLs12]-icode9专业技术文章分享
- 2024-07-05怎么清理项目缓存-icode9专业技术文章分享
- 2024-07-04安装 Eyoucms详细图文教程-icode9专业技术文章分享
- 2024-07-04ueditor 复制文章时,图片的链接是一个下载图片地址,该如何处理?-icode9专业技术文章分享
- 2024-07-04怎样判断host有没有对wordpress有缓存呢-icode9专业技术文章分享
- 2024-07-04具有编译功能的系统make后,无法ssh连接-icode9专业技术文章分享
- 2024-07-04make后如何升级ssh-icode9专业技术文章分享