• 忘记了释放内存,造成内存泄露


    忘记了释放内存,造成内存泄露。

    含有这种错误的函数每被调用一次就丢失一块内存。

    刚开始时系统的内存充足,你 看不到错误。

    终有一次程序突然死掉,系统出现提示:内存耗尽。

    动态内存的申请与释放必须配对,程序中 malloc 与 free 的使用次数一定要相同,否 则肯定有错误(new/delete 同理)。

     1 #include <iostream>
     2 #include <string.h>
     3 
     4 //main()函数
     5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     6 
     7 using namespace std;
     8 int main(int argc, char** argv) {
     9    //声明字符数组
    10     char string[80],*p;
    11     int i;
    12 
    13     //转换字符串中的小写字母为大写
    14     cout<<"Convert a string to uppercase:"<<endl;
    15     cout<<"string:";
    16     cin>>string;
    17     p=strupr(string);
    18     cout<<"p:"<<p<<endl;
    19     cout<<"string:"<<string<<endl;
    20     cout<<"----------------------"<<endl;
    21 
    22     //转换字符串中的大写字母为小写
    23     cout<<"Convert a string to lowercase:"<<endl;
    24     cout<<"string:";
    25     cin>>string;
    26     p=strlwr(string);
    27     cout<<"p:"<<p<<endl;
    28     cout<<"string:"<<string<<endl;
    29     return 0;
    30 }
  • 相关阅读:
    如何使用Flannel搭建跨主机互联的容器网络
    移动端——touch事件
    Javascript 模块化指北
    vue重构--H5--canvas实现粒子时钟
    redux-saga框架使用详解及Demo教程
    前端代码编写规范
    探秘JS的异步单线程
    POJ 3714 Raid 近期对点题解
    EditText把回车键变成搜索
    Swift语言概览
  • 原文地址:https://www.cnblogs.com/borter/p/9413662.html
Copyright © 2020-2023  润新知