淡水求咸

博客园已经停止更新,请移步 http://lovecjh.com/

导航

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 22 下一页

2012年3月13日

C++数组名解析

摘要: 首先看下面程序:#include <iostream>using namespace std;int main(){ int a[5]={0,1,2,3,4}; cout<<a<<endl; cout<<&a<<endl; cout<<a+1<<endl; cout<<&a+1<<endl; return 0;}运行结果:0012FF6C0012FF6C0012FF700012FF80解析:(1)a是数组名,代表数组第一个元素地址,a+1是数组第二个元素的地址。 (2)& 阅读全文

posted @ 2012-03-13 12:56 深圳彦祖 阅读(1842) 评论(0) 推荐(1) 编辑

2012年3月12日

C++一道面试题(atexit)

摘要: 题:main主函数执行完毕后,是是否可能会再执行一段代码?给出说明。答:如果需要加入一段在main退出后执行的代码,可以使用atexit()函数注册一个函数,代码如下:#include <stdio.h>#include <stdlib.h>int atexit(void(*function)(void));void fn1(void),fn2(void),fn3(void),fn4(void);int main(){ atexit(fn1); atexit(fn2); atexit(fn3); atexit(fn4); printf("This is exe 阅读全文

posted @ 2012-03-12 09:41 深圳彦祖 阅读(398) 评论(0) 推荐(0) 编辑

2012年3月10日

C++中的位拷贝和值拷贝

摘要: 原文:http://blog.csdn.net/liam1122/article/details/1966617 为了便于说明我们以String类为例: 首先定义String类,而并不实现其成员函数。 Class String{ public: String(const char *ch=NULL);//默认构造函数 String(const String &str);//拷贝构造函数 ~String(void); String &operator=(const String &str);//赋值函数 private: ... 阅读全文

posted @ 2012-03-10 15:16 深圳彦祖 阅读(4534) 评论(0) 推荐(2) 编辑

2012年3月9日

C++中delete与delete[]

摘要: 这篇文章是CSDN C++论坛中多次讨论到的一个问题。先看下面程序:#include <iostream>using namespace std;#include <string>int main(){ int *p=new int[5]; //delete p; delete []p; p=NULL; //string *p=new string[5]; //delete p; //delete []p; //p=NULL; return 0;}对于int类型和string类型,delete p和delete []p编译器(vc6.0)会... 阅读全文

posted @ 2012-03-09 14:16 深圳彦祖 阅读(3712) 评论(0) 推荐(0) 编辑

2012年3月8日

C++继承中的虚析构函数

摘要: 看看下面程序有什么错误:#include <iostream>using namespace std;class Father{public: Father(){}; ~Father(){};};class Son:public Father{public: Son(){}; ~Son(){};};int main(){ Father *pfather=new Son; delete pfather; pfather=NULL; return 0;}该程序在VC++6.0运行后并未发生错误,何解?修改上面程序如下:#include <iostre... 阅读全文

posted @ 2012-03-08 14:32 深圳彦祖 阅读(3450) 评论(0) 推荐(0) 编辑

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 22 下一页