摘要:
代码:#include<iostream>
using namespace std;
class A
{ };
class B
{ char a; int b;
};
class C
{ void foo(){};
};
class D
{ virtual void foo(){};
};
int main()
{ cout<<sizeof(A)<<sizeof(B)<<sizeof(C)<<sizeof(D); return 0;
}疑:结果是什么,为什么呢?解答:sizeof(A)为1,而不是0,虽然空类没有任何成员变量,但其实体 阅读全文
posted @ 2011-07-06 01:11
程序员新鲜事
阅读(190)
评论(0)
推荐(0)
摘要:
代码:#include<iostream>
using namespace std;
int main()
{ char *str1 = "string"; char *str2 = "string"; if(str1 == str2) cout<<"str1 is same as str2";
}疑:str1 的值是否等于 str2 而输出字符串“str1 is same as str2”呢,为什么?解答:是的 “str1 is same as srr2”,也就是说str1与str2指向了相同的内存地址,因为 阅读全文
posted @ 2011-07-06 00:37
程序员新鲜事
阅读(149)
评论(0)
推荐(0)
摘要:
代码:#include<iostream>
using namespace std;
void foo(int p1,int p2,int p3)
{ cout<<"p1="<<p1<<endl <<"p2="<<p2<<endl <<"p3="<<p3<<endl;
}
int main()
{ int i; cout<<"first call:"<<endl; i=0; 阅读全文
posted @ 2011-07-06 00:24
程序员新鲜事
阅读(135)
评论(0)
推荐(0)
浙公网安备 33010602011771号