首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

每日一道C\C++笔试题V-内存泄露

2013-03-12 
每天一道C\C++笔试题V---内存泄露俗语云:出来混,迟早是要还的。下面是一道初级内存泄露题,程序员小懒儿显式

每天一道C\C++笔试题V---内存泄露

俗语云:出来混,迟早是要还的。

下面是一道初级内存泄露题,程序员小懒儿显式的用new动态分配了内存,却忘记了用delete释放。

请找出问题的所在,代码如下:

//linc//2013.3.7//C++ memory leak ,case 1#include <iostream>#include <cstring>using namespace std;class Student{int student_number;char* name;public:Student(int,char*);virtual ~Student();};Student::Student(int number,char* _name){student_number = number;name = new char[strlen(_name)+1];strcpy(name,_name);cout<<"student_number is "<<student_number<<endl;cout<<"name is "<<name<<endl;}//hereStudent::~Student(){delete name;}int main(){Student *student = new Student(123,"linc");delete student;return 0;}




热点排行