当前位置: 首页 > news >正文

网站统计查询公众出行服务网站建设

网站统计查询,公众出行服务网站建设,秦皇岛乾兴建设,台州学校网站建设内存管理 new/delete C语言 malloc free完成对堆内存的申请和释放。 C new delete 类 new#xff1a;动态申请存储空间的运算符#xff0c;返回值为申请空间的对应数据类型的地址 int *p new int(10); 申请了一个初始值为10的整型数据 int *p new int[10]; 申…内存管理 new/delete C语言  malloc  free完成对堆内存的申请和释放。 C  new  delete 类 new动态申请存储空间的运算符返回值为申请空间的对应数据类型的地址 int *p new int(10);  申请了一个初始值为10的整型数据 int *p new int[10];   申请了能存放10个整型数据元素的数组其首地址为arr 单变量空间 #include iostream #include stdlib.h using namespace std;//malloc free # include stdlib.h 库函数 //new delete key work 关键字int main() {//Cint *p (int*)malloc(sizeof(int));int *p static_castint*(malloc(sizeof(int)));//C 单变量空间int *p new int(200);//*p 200;cout*pendl;string *ps new string(aaa);//*ps china;cout*psendl;struct Stu{int age;string name;};Stu *pStu new Stu{10, bob};coutpStu-ageendl;coutpStu-nameendl;return 0; } 多变量空间  数组 #include iostream #include string.h // #include cstring #include stdlib.h using namespace std;int main() {char* p new char[4];const char* source aa;strcpy_s(p, 4, source);cout p: p endl;int *pi new int[5]{0};memset(pi, 0, sizeof(int[5]));for(int i 0; i 5; i){coutpi[i]endl;}char **ppc new char*[5]{NULL};ppc[0] new char[10];strcpy(ppc[0], china);ppc[1] automan;ppc[2] greatwall;while(*ppc){cout*ppcendl;}return 0; } 一维、多维 #include iostream #include stdlib.h #include string.h using namespace std;int main() {int(*pa)[4] new int[3][4]{ {0} };for (int i 0; i sizeof(int[3][4]) / sizeof(int[4]); i){for (int j 0; j 4; j){cout pa[i][j] ;}cout endl;}int (*px)[3][4][5] new int[2][3][4][5];return 0; } 内存释放 #include iostream #include stdlib.h #include string.h using namespace std;int main() {int *p new int;delete p;int *q new int[1000];delete []q;//多维只用一个框即可内核用递归删除int *r new int[1000][][];delete []r;return 0; } 内联函数 内联函数inline function 介于宏函数和普通函数之间 宏函数 优点代码内嵌避免了函数调用。 缺点容易产生歧义易使text段体积增大。 普通函数 优点一段高度抽象的逻辑不易产生歧义使text段体积减小。 缺点函数调用的压栈与出栈的开销。 inline 内联函数 优点一段高度抽象的逻辑不易产生歧义使text段体积减小会进行类型检查避免压栈与出栈的开销。 代价增加代码段的空间 本质以牺牲代码段空间为代价提高程序的运行时间的效率 适用代码体很小且频繁调用 为何不把所有函数inline 内嵌太多inline变成了给编译器的一种建议 只有当函数只有10行甚至更少时才会将其定义为内联函数。 #include iostream using namespace std;#define SQR(i) ((i)*(i)) //宏函数int sqr(i) //普通函数 {return i * i; }inline int sqr(i) {return i * i; }int main() {int i 0;while(i 5){coutSQR(i)endl;}return 0; } 强制类型转换 #include iostream #include stdlib.husing namespace std;void func(int v) {coutvendl; }int main() {static_cast 对于隐式类型可以转化的即可用此类型float a 5.6;int b 5;//隐式类型转换a b;b a;b static_castint(a);a static_castfloat(b);void *p; int *q;p q;q p; //报错q static_castint*(p);int x 10;int y 3;float z static_castfloat(x) / y;char * pc static_castchar*(malloc(100));reinterpret_cast 对于无隐式的类型转化static_cast不可用char * p; int * q;p reinterpret_castchar*(q);int a[5] {1, 2, 3, 4, 5};int *p (int*)((int)a1);int *p reinterpret_castint*((reinterpret_castint(a) 1));couthex*pendl;const_cast 脱常只能应用于指针和引用const 修饰的一定不可以改const int a 19;func(const_castint(a));dynamic_castreturn 0; } 宏在预处理阶段发生了替换 常量编译阶段发生了替换 常量不变 命名空间 命名空间为大型项目开发避免命名冲突的一种机制。 :: 作用域运算符前面要命名空间 全局无名命名空间 局部 namespace  是对全局命名空间的再次划分。 #include iostreamusing namespace std;int v 55; // 全局int main() {int b 10; // 局部int *p v;coutvendl;coutbendl;cout::endl;return 0; } #include iostreamusing namespace std;namespace Space{int x;void func(){printf(void func);}struct Stu{int a;int b;} }namespace Other{int x;int y; }int main() {Space::x 200;coutSpace::xendl;using Space::x;x 20;coutxendl;using namespace Space;Stu s {1, 2};cout s.a --- endl;using namespace Other;Other::x 10;y 20;coutOther::xyendl;int m, n;std::cinmn;std::coutmnstd::endl;return 0; } 如果有局部变量名相同冲突 支持嵌套 #include iostreamusing namespace std;namespace Space{int a;int b;namespace Other{int m;int n;} }int main() {using namespace Space::Other;m 20;return 0; } 协作开发 #include iostreamusing namespace std;namespace Space {int x; }namespace Space {int y; }int main() {using namespace Space;int x 10;int y 20;coutxyendl;return 0; } 相同空间名会合并 String类 #include iostreamusing namespace std;//string 不是关键字而是一个类int main() {std::string str;string str(china);string str china;str good;string str2(str);coutstrendl;coutstr2endl;string s china;s[3] w;coutsendl;char buf[1024];strcpy(buf, s.c_str()); //string - char* c_str返回字符串coutbufendl;str.swap(str2); //交换两个字符串 swap 成员函数int n str.find(i, 0); //查找一个字符的位置返回下标找不到返回-1coutn nendl;string sArray[10] {0,1,22,333,4444,55555,666666,7777777,88888888,999999999,};for(int i 0; i 10; i){coutsArray[i]endl;}return 0; } 总结 malloc free C库函数    new delete  new[]  delete[] 关键字 new delete malloc free 申请单变量空间 申请数组  一维  多维 #include iostreamusing namespace std;struct Str {char *p; };int main() {string *ps new string;*ps china;coutpsendl; //输出地址 对象的地址cout*psendl; //输出值 对象的内容struct Str str {abcdefg};int *pi new int[10]{0};char **ppc new int*[5]{NULL}; //定义指针数组int (*p)[4] new int[3][4];return 0; } erase(0, npos) 从0开始一直删除到 位置 str.erase(0, str.find_first_not_of( )); 下标后往后删除 str.erase(str.find_last_not_of( ) 1); #include iostream #include string.h #include stdlib.husing namespace std;int main() {FILE *fp fopen(aa.txt, r); //打开并读取文件if(fp NULL)return -1;vectorstring vs;char buf[1024];while(fgets(buf, 1024, fp) ! NULL) //读取文件内容{vs.push_back(buf); // 内容接在后边}for(int i 0; i vs.size(); i){coutvs[i]endl;}fclose(fp);return 0; }
http://www.dnsts.com.cn/news/213317.html

相关文章:

  • 网站建设制作模板网站怎么做爱主题 wordpress
  • 临沂seo建站移动端网站如何开发
  • 做网站一次付费潍坊程序设计网站建设公司
  • 成都网站开发定制建站运营新闻
  • 江西工程建设信息网站gzip压缩网站
  • 全球网站流量排名查询桂林山水甲天下是哪个景点
  • 成品网站 智能建站企业网站推广目标
  • 内部建设网站需要什么条件手机直播软件
  • 网站设计一般多少钱一个页面深圳建设工程价格信息网站
  • 沧州模板建站平台网站栏目规划怎么写
  • 建设网站要花多少钱做外贸哪个网站看外汇
  • 网站建设如何交税网站模板侵权问题
  • 网站域名后缀区别石家庄网站建设吧
  • 公司网站建设公司php做网站需要注意什么
  • 中华智能自建代理网站做网站市场分析
  • 专业做酒店网站国家域名注册中心
  • 网站建设工程师职责网站备案有幕布
  • 西安企业自助建站企业免费自助建站系统
  • 东港建站公司玉溪网站建设公司
  • 电子商务网站开发与应用论文邢台网站制作市场
  • 河南网站推广优化多少钱的品质网站建设
  • 铁总建设函网站动漫制作专业毕业答辩是什么内容
  • 网站开发 前端清风夏邑进入公众号
  • 网站一般宽度郑州app开发
  • 建网站app需要多少钱萝岗网站开发
  • 桂林 网站 建设中文外贸网站建设
  • 企业网站建设代理加盟自己做网站系统首选平台
  • 中山网站建设是什么意思最好的营销型网站建设公司
  • 设计商城网站 优帮云wordpress文章修改大小
  • 绵阳 网站开发 公司景德镇网站建设哪家口碑好