http://www.mianwww.com/html/2013/10/19128.html
http://blog.csdn.net/wdzxl198/article/details/9050751
http://www.cnblogs.com/fangyukuan/archive/2010/09/18/1829871.html
http://blog.csdn.net/blue4689/article/details/6599592
1)将“引用”作为函数参数有哪些特点?
1.传递引用给函数与传递指针的效果是一样的,使用指针作为函数的参数虽然也能达到与使用引用的效果,但是,在被调函数中同样要给形参分配存储单元
2.使用引用传递函数的参数,在内存中并没有产生实参的副本,它是直接对实参操作;而使用一般变量传递函数的参数,当发生函数调用时,需要给形参分配存储单元,形参变量是实参变量的副本;如果传递的是对象,还将调用拷贝构造函数。因此,当参数传递的数据较大时,用引用比用一般变量传递参数的效率和所占空间都好。
2)结构与联合的区别
1. 结构和联合都是由多个不同的数据类型成员组成, 但在任何同一时刻, 联合中只存放了一个被选中的成员(所有成员共用一块地址空间), 而结构的所有成员都存在(不同成员的存放地址不同)。
2. 对于联合的不同成员赋值, 将会对其它成员重写, 原来成员的值就不存在了, 而对于结构的不同成员赋值是互不影响的。
Union的大小为其内部所有变量中的最大值,并且按照类型最大值的整数倍进行内存对齐
union A { char c[10]; char cc1; }; union B { char c[10]; int i; }; union C { char c[10]; double d; }; union D { char c; int i; double d; }; void main() { cout << sizeof(A) << " " << sizeof(B) << " " << sizeof(C) << " " << sizeof(D) << endl; system("pause"); } //输出:10 12 16 8
3)关于联合的一道输出题
union { int i; char x[2]; }a; void main() { a.x[0] = 10; a.x[1] = 1; printf("%d", a.i); }
输出266,低位低地址,高位高地址,内存占用情况是Ox0000 010A
4)实现string类
class String { public: String(const char *str = NULL); // 通用构造函数 String(const String &another); // 拷贝构造函数 ~String(); // 析构函数 String& operater =(const String &rhs); // 赋值函数 private: char* m_data; // 用于保存字符串 }; String::String(constchar*str) { if ( str == NULL ) // strlen在参数为NULL时会抛异常才会有这步判断 { m_data =newchar[1] ; m_data[0] ='