zoukankan      html  css  js  c++  java
  • 内存耗尽怎么办?

    内存耗尽怎么办?

    如果在申请动态内存时找不到足够大的内存块,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 }
  • 相关阅读:
    在Eclipse中使用Checkstyle 检查Java代码规范
    文件缓存法的具体实现
    hdu 4454 Stealing a Cake
    uva 11922
    uva 11020
    uva 12206
    uva 11107
    uva 11796
    uva 11178
    uva 11437
  • 原文地址:https://www.cnblogs.com/borter/p/9406457.html
Copyright © 2011-2022 走看看