发布时间:2013-01-15 18:57:06
#include "stdafx.h"#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ char a[] = "hello"; a[0] = 'X'; cout<<a<<endl; char *p ="world"; p[0] = 'x'; cout<<p<<endl; return 0;} 第二条时,"world"是.........【阅读全文】
发布时间:2013-01-15 18:11:46
delete和delete[]都可以删除已经分配的内存,但是两者有所不同。例如:程序1#include <iostream> int main() { char *str=new char[4]; delete [] str;//or use delete str; return 0; }程序2#include <iostream> int main() { char *str=new char[4]; dele.........【阅读全文】
发布时间:2013-01-04 10:53:17
#include "stdafx.h"#include <iostream>using namespace std; template <class T> void swap_pri(T& a, T& b){ T c; c=a; a=b; b=c;} int _tmain(int argc, _TCHAR* argv[]){ int a1 = 5; int b1 = 3; swap_pri(a1,b1); cout<< "a = "<<a1<......【阅读全文】
发布时间:2013-01-01 23:06:23
内联函数从源代码层看,有函数的结构,而在编译后,却不具备函数的性质。编译时,类似宏替换,使用函数体替换调用处的函数名。一般在代码中用inline修饰,但是能否形成内联函数,需要看编译器对该函数定义的具体处理。 #include "stdafx.h" #define swap1(a,b) {int c;c=a;a=b;b=c;}#define swap2(a,b) {a^=b,b^=a;a^=b;} inline void swap3(int &a,int &b);void swap3(int &a,int &b){&......【阅读全文】