码迷,mamicode.com
首页 > 编程语言 > 详细

c++拓展register寄存器

时间:2019-02-10 09:18:26      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:public   system   inf   ons   linux   cout   没有   android   rod   

寄存器----硬件和软件打交道的接口,这上面装了android,亦或是 windows,linux就能和相关的操作系统设备打交道
技术图片

技术图片

技术图片


早期硬件性能并不很快时,为了提高程序运行的效率,会声明一个寄存器变量,这样一来相当于埋好了“伏笔”,省去了现场开辟空间,再赋值的麻烦 register
int a = 10 但是C语言寄存器变量没有地址一说,所以这类写法是错误的 printf("%p",&a); c++中,支持register,但也有其他优化程序的手段,而且,C++中可以取得寄存器中的变量地址!!! 例如for循环中的计数器变量i,放到寄存器中,加快程序的执行速度 c++编译器发现有register变量的取地址操作时,register对变量的声明无效 由于早期C语言不具备优化功能,register变量是个有益的补充 c++有变量检测功能对于 char myname[10] = {}; charmyname[10] = "猴儿厉"; 这种代码可以通过 vc++6.0的编译! 如果,调用printf打印变量myname,那么取哪个呢,所以在c++中这么声明就会提示错误 另外在c++中struct和class完成的功能类似 struct mycoach { private: string name; int age; public: void introduceyouself(string _name,int _age) { name=_name; age=_age; cout<<name<<age; } } c++加强了对类型的检查-----变量必须带数据类型 而在c中,下述代码居然能够出现!!! f() { printf("%d".i); } c++中布尔变量,要不为0,要不为1,即使给布尔值赋值为负数结果也为1 sizeof()用于测定变量所占空间大小 三目运算符,左值的概念,表达式的值即是变量本身 void main() { int a = 10; int b = 20; (a < b ? a : b) = 30; printf("a=%d\n",a); printf("b=%d\n",b); //coachnamespace::mycoach mc; system("pause"); } 常量 const int a; int const a; int * const a; const int *a

 

c++拓展register寄存器

标签:public   system   inf   ons   linux   cout   没有   android   rod   

原文地址:https://www.cnblogs.com/saintdingspage/p/10358562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!