常用路由协议
posted @ 2008-01-31 21:24 浴盆 阅读(159) 评论(0) 编辑
posted @ 2008-01-31 21:19 浴盆 阅读(342) 评论(0) 编辑
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a;
cin>>b;
cout<<"交换前"<<endl;
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;

a = a+b;
b = a -b;
a = a -b;
cout<<"交换后"<<endl;
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
return 0;
}posted @ 2008-01-31 20:34 浴盆 阅读(388) 评论(7) 编辑
#include<iostream>
using namespace std;
int main()
{
typedef union {long i; int k[5]; char c;} DATE;
struct data { int cat; DATE cow; double dog;} too;
DATE max;
cout<<"sizeof(struct date)+sizeof(max) = "<<sizeof(too)+sizeof(max)<<endl;
cout<<"sizeof(too) = "<<sizeof(too)<<endl;
cout<<"sizeof(max) = "<<sizeof(max)<<endl;
cout<<"struct data.cow size = "<<sizeof(too.cow)<<endl;
cout<<"union DATE.i size = "<<sizeof(max.i)<<endl;
cout<<"union char.c size = "<<sizeof(max.c)<<endl;
}
#include<iostream>
using namespace std;
int main()
{
typedef union student
{
char name[10];
long sno;
char sex;
float score [4];
} STU; 
STU a[5];
cout<<sizeof(a)<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
typedef struct student
{
char name[10];
long sno;
char sex;
float score [4];
} STU; 
STU a[5];
cout<<sizeof(a)<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
typedef struct student
{
char name[10];
char sex;
long sno;
float score [4];
} STU; 
STU a[5];
cout<<sizeof(a)<<endl;
return 0;
} 答案是:160. 为什么,只是换了顺序而已呀?关键就在顺序上。
结构体中,size最大的是long,size是 4,所以,按照顺序,Char name[10];12个字节;但是这12中多分配的2个字节可以包含后面的Char sex; (问题就在这);Float score [4]; 16个字节。于是(12+4+16)×5=160
posted @ 2008-01-31 17:42 浴盆 阅读(862) 评论(0) 编辑
#include<iostream>
using namespace std;
int main()
{
typedef union {long i; int k[5]; char c;} DATE;
struct data { int cat; DATE cow; double dog;} too;
DATE max;
cout<<"sizeof(struct date)+sizeof(max) = "<<sizeof(too)+sizeof(max)<<endl;
cout<<"sizeof(too) = "<<sizeof(too)<<endl;
cout<<"sizeof(max) = "<<sizeof(max)<<endl;
cout<<"struct data.cow size = "<<sizeof(too.cow)<<endl;
cout<<"union DATE.i size = "<<sizeof(max.i)<<endl;
cout<<"union char.c size = "<<sizeof(max.c)<<endl;
}posted @ 2008-01-31 17:33 浴盆 阅读(92) 评论(0) 编辑
全局变量(外部变量)的说明之前再冠以static 就构成了静态的全局变量。全局变量本身就是静态存储方式, 静态全局变量当然也是静态存储方式。这两者在存储方式上并无不同。这两者的区别虽在于非静态全局变量的作用域是整个源程序, 当一个源程序由多个源文件组成时,非静态的全局变量在各个源文件中都是有效的。 而静态全局变量则限制了其作用域, 即只在定义该变量的源文件内有效, 在同一源程序的其它源文件中不能使用它。由于静态全局变量的作用域局限于一个源文件内,只能为该源文件内的函数公用, 因此可以避免在其它源文件中引起错误。
static全局变量与普通的全局变量有什么区别:static全局变量只初使化一次,防止在其他文件单元中被引用;
static局部变量和普通局部变量有什么区别:static局部变量只被初始化一次,下一次依据上一次结果值;
static函数与普通函数有什么区别:static函数在内存中只有一份,普通函数在每个被调用中维持一份拷贝。
posted @ 2008-01-31 17:14 浴盆 阅读(2198) 评论(0) 编辑
局部变量在使用时会屏蔽全局变量。要用全局变量,需要使用"::".
局部变量可以与全局变量同名,在函数内引用这个变量时,会用到同名的局部变量,而不会用到全局变量。对于有些编译器而言,在同一个函数内可以定义多个同名的局部变量,比如在两个循环体内都定义一个同名的局部变量,而那个局部变量的作用域就在那个循环体内。
#include<iostream>
using namespace std;
void test();
int i = 1;
int main()
{
int i = 2;
cout<<"global i = "<<::i<<" "<<"address = "<<&::i<<endl;
cout<<"main() i = "<<i<<" "<<"address = "<<&i<<endl;
test();
{
cout<<"main() i = "<<i<<" "<<"address = "<<&i<<endl;
int i = 3;
cout<<"local i = "<<i<<" "<<"address = "<<&i<<endl;
}
}
void test()
{
int i = 4;
cout<<"test() i = "<<i<<" "<<"address = "<<&i<<endl;
cout<<"global i = "<<::i<<" "<<"address = "<<&::i<<endl;
}
posted @ 2008-01-31 17:01 浴盆 阅读(760) 评论(0) 编辑