• 内存耗尽怎么办?


    内存耗尽怎么办?

    如果在申请动态内存时找不到足够大的内存块,malloc 和 new 将返回 NULL 指针, 宣告内存申请失败。通常有三种方式处理“内存耗尽”问题。

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 int main(int argc, char** argv) {
     6     //声明变量和指针变量
     7     int a,b,c,*ip;
     8 
     9     //指针变量ip指向变量a
    10     a=100;
    11     ip=&a;        //使指针变量 ip 指向变量a
    12     cout<<"a="<<a<<endl;
    13     cout<<"*ip="<<*ip<<endl;
    14     cout<<"ip="<<ip<<endl;
    15 
    16     //指针变量ip指向变量b
    17     ip=&b;        //使指针变量 ip 指向变量b
    18     b=200;
    19     cout<<"b="<<b<<endl;
    20     cout<<"*ip="<<*ip<<endl;
    21     cout<<"ip="<<ip<<endl;
    22 
    23     //指针变量ip指向变量c
    24     ip=&c;        //使指针变量 ip 指向变量b
    25     *ip=a+b;
    26     cout<<"c="<<c<<endl;
    27     cout<<"*ip="<<*ip<<endl;
    28     cout<<"ip="<<ip<<endl;
    29     return 0;
    30 }
  • 相关阅读:
    mybatis框架快速入门
    perl FileHandle 模块使用
    perl substr
    Browse Code Answers
    无题
    dlang 泛型
    dlang 读取gz压缩文件
    R包 tidyverse 分列
    推荐一个网站:用各种语言去做同一件事
    dlang ref的作用
  • 原文地址:https://www.cnblogs.com/borter/p/9406457.html
Copyright © 2020-2023  润新知