码迷,mamicode.com
首页 > 其他好文 > 详细

内存耗尽怎么办?

时间:2018-08-02 12:51:52      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:申请   you   sys   cout   class   space   处理   ram   oop   

内存耗尽怎么办?

如果在申请动态内存时找不到足够大的内存块,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 }

 

内存耗尽怎么办?

标签:申请   you   sys   cout   class   space   处理   ram   oop   

原文地址:https://www.cnblogs.com/borter/p/9406457.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!