++i vs i++
【分析】
i++与++i哪个效率更高?
(1)在内建数据类型的情况下,效率没有区别;
(2)在自定义数据类型Class的情况下,++i效率更高!
自定义数据类型的情况下:++i返回对象的引用;i++总是要创建一个临时对象,在退出函数时还要销毁它,而且返回临时对象的值时还会调用其拷贝构造函数。
【代码】
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#include <stdio.h>
#include <stdlib.h> #include <string.h> #include <vector> #include <iostream> using namespace std; class Integer // ++i first +1,then return new value // i++ first save old value,then +1,last return old value void output() void test_case() int main() |
最新文章
- Onsen UI – 新鲜出炉的 PhoneGap 界面框架
- MVC数据验证原理及自定义ModelValidatorProvider实现无编译修改验证规则和错误信息
- 资源搜集:Git精品文章推荐,常年更新
- 关于ImageMagick出现无效参数(invalid parameter)的解决方法
- c# 搭建服务端 传输协议(2)
- Ubuntu 13.04/12.10安装Oracle 11gR2图文教程(转)
- OpenCV2第一个马拉松8环——画一个柱状图
- GridControl基础设置(一)
- [NOI2017]泳池
- Docker Dockerfile
- web移动端区分Android或者ios系统
- Android--UI之ListView
- WebApi参数传递实例
- JS计算前一天或后一天,前一月后一月
- cxRichEdit1获取EXCEL的区域图片
- css3统一元素的宽和高
- java读取记事本文件第一个字符遇到的一个坑
- Mac下终端(terminal)的一些快捷键
- kendo-ui的MVVM模式
- SSH电力项目四-显示首页