摘要:
一个程序咋爱内存占用的存储空间可以分为:程序区:用来存放可执行程序的程序代码的。静态存储区:静态变量,在程序开始执行时分配,在执行过程中是固定的,程序执行完后释放空间。动态存储区:动态变量和形参以及函数调用时的现场保护程序和返回地址等。auto变量(动态变量):C++编译器默认局部变量为自动变量。不需要auto关键字说明。若没有明确赋值,其初值是不确定的。int fun(int n){ auto int a; int b = 20;}static变量:静态变量static int x;//静态全局变量int fun(int n){ static int a;//静态局部变量,仍保留上一次函数调 阅读全文
摘要:
C++ 函数间的参数传递:传值,引用和地址void swap(int a, int b){ int t; t=a; a=b; b=t;}void main{ int a=10, b=20; cout<<"Before:a="<<a<<"\t"<<"b="<<b<<"\n"; swap(a,b); cout<<"After:a="<<a<<"\t"<<&quo 阅读全文
摘要:
int *y = new int; *y = 10; 或者 int *y = new int (10); 或者 int *y; y = new int (10); 一维数组: float *x = new float [n]; 在Borland C++中,当new 不能分配足够的空间时,它会引发(t h r o w)一个异常xalloc (在except.h 中定义)。可以采用try - ca... 阅读全文
摘要:
传值函数:int Abc(int a, int b, int c){ return a+b+b*c+(a+b-c)/(a+b)+4;}模板函数:template<class T> T Abc(T a, T b, T c){ return a+b+b*c+(a+b-c)/(a+b)+4;}形式参数的用法会增加程序的运行开销类型T 的复制构造函数把相应的实际参数分别复制到形式参数a,b和... 阅读全文
摘要:
1a. choose rows where column 3 is larger than column 5:awk '$3>$5' input.txt > output.txt1b. calculate the sum of column 2 and 3 and put it at the end of a row:awk '{print $0,$2+$3}' input.txtor replace the first column:awk '{$1=$2+$3;print}' input.txt2. show rows betwe 阅读全文