博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符串不同存储形式代表的不同数据类型 及 返回值为引用要十分注意
阅读量:2804 次
发布时间:2019-05-13

本文共 940 字,大约阅读时间需要 3 分钟。

#ifndef _TEST_H#define _TEST_H#include 
using namespace std;char* func(){ char *ch = "hello world"; //can do like this because this is a static data member,it stored in a static data area,will not be released after the func //char ch[] = "hello world"; //can not do like this because ch[] is on stack, it will be released when the func finish return ch;}//it not safe because c is a local variable, it will be released when the func1 finish and will be used by others without any protection//but the return value record the adress of cint& func1(){ int a = 1; int b = 2; int c; c = a+b; cout << &c << endl; cout << c << endl; return c;}int main(){ int& result = func1(); cout << &result << endl; cout << result << endl; int &r = result; cout << &r << endl; cout << r << endl; //test the data type of a string when it represent in different ways /*char *result; result = func(); cout << result << endl; return 0;*/}#endif //_TEST_H
 

转载地址:http://vonmd.baihongyu.com/

你可能感兴趣的文章
游戏服务端究竟解决了什么问题?
查看>>
mongodb集合中查询文档
查看>>
关联规则挖掘——Apriori算法的基本原理以及改进
查看>>
决策树之ID3算法
查看>>
朴素贝叶斯算法
查看>>
聚类分析经典算法讲解及实现
查看>>
mongodb中使用分组,聚合和映射-归并
查看>>
使用java连接mongodb数据库,并访问集合
查看>>
java对mongodb数据库的增删改查
查看>>
决策树之ID3算法实现(python)
查看>>
数据预处理
查看>>
大型数据库中的关联规则挖掘
查看>>
Apriori算法
查看>>
linux:shell中>,>>,<的含义
查看>>
java当前路径和相对路径相关的疑惑
查看>>
远程给局域网中的计算机进行重启或者关机
查看>>
java数据库连接池
查看>>
PicGo + Gitee(码云)实现markdown图床
查看>>
高性能服务器架构(三):分布式缓存
查看>>
PowerEdge R430 机架式服务器安装( Ubuntu server 14.04.1 、PHP5.5.9、PHP-redis2.8、Phalcon3.1)...
查看>>