首页 > 代码库 > 一切为了笔试~
一切为了笔试~
1 //sizeof的使用
2 char a[30]="abcde";
3 char *b=new char[20];
4 cout<<sizeof(a)<<endl;//30
5 cout<<sizeof(b)<<endl;//4
6 cout<<sizeof(a[3])<<a[3]<<endl;//1
7 cout<<sizeof(b+3)<<endl;//4
8 cout<<sizeof(*(b+4))<<endl;//1
9
10 class A
11 {
12 };
13
14 class B
15 {
16 };
17
18 class C
19 {
20 };
21 class G
22 {};
23
24 class D:public A
25 {
26 };
27
28 class E:public A,B
29 {
30 };
31
32 class F:public A,B,C,G
33 {
34 };
35 cout<<"void (D::*)()的大小是:"<<sizeof( void (D::*)() )<<endl; // 4
36 cout<<"void (E::*)()的大小是:"<<sizeof( void (E::*)() )<<endl; // 8
37 cout<<"void (F::*)()的大小是:"<<sizeof( void (F::*)() )<<endl; // 8
38 cout<<"void* 的大小是:"<<sizeof( void(*) )<<endl; //4
2 char a[30]="abcde";
3 char *b=new char[20];
4 cout<<sizeof(a)<<endl;//30
5 cout<<sizeof(b)<<endl;//4
6 cout<<sizeof(a[3])<<a[3]<<endl;//1
7 cout<<sizeof(b+3)<<endl;//4
8 cout<<sizeof(*(b+4))<<endl;//1
9
10 class A
11 {
12 };
13
14 class B
15 {
16 };
17
18 class C
19 {
20 };
21 class G
22 {};
23
24 class D:public A
25 {
26 };
27
28 class E:public A,B
29 {
30 };
31
32 class F:public A,B,C,G
33 {
34 };
35 cout<<"void (D::*)()的大小是:"<<sizeof( void (D::*)() )<<endl; // 4
36 cout<<"void (E::*)()的大小是:"<<sizeof( void (E::*)() )<<endl; // 8
37 cout<<"void (F::*)()的大小是:"<<sizeof( void (F::*)() )<<endl; // 8
38 cout<<"void* 的大小是:"<<sizeof( void(*) )<<endl; //4
int test(int j)
{
static int i=10;
i=i+j;
return i;
}
//static的使用
cout<<test(12)<<endl;//22
{
static int i=10;
i=i+j;
return i;
}
//static的使用
cout<<test(12)<<endl;//22
cout<<test(4)<<endl;//26
1 class A
2 {
3 int x;
4 double d;
5 };
6 A a[10];
7 cout << sizeof(A) << endl; // 输出:16,此处有内存补齐,所以不是12
8 cout << sizeof(a) << endl; // 输出:160
一切为了笔试~
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。